![]() |
|
![]() |
| LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Junior Member Join Date: Jul 2009 Location: indore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1 | girdview edit I’m using the GridView in asp.net and populating the grid dynamically using c#.net.To edit the rows i m using GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e). Now if I run the application and click the “Edit” Button then the complete row is generating the textboxes to edit the data in that particular row and also the “Update” and “Cancel” buttons are generated.When I change the data in any of the textboxes in that row then how should I Update that data to the Database(Sql server) using stored procedure . and display the updated data in the grid.Plzzz provide the code for this and also Is the same thing applies to the delete button.Plzzzzz help.. i m sending my code plz tell me where is d error.. gridview.aspx stored procedure Editdata ALTER PROCEDURE [dbo].[EditData] @name as varchar(50) , @password as varchar(20) AS BEGIN SET NOCOUNT ON; update [dbo].[Login] set [pwd]= @password where [uid]=@name END gridview.aspx.cs public partial class gridview : System.Web.UI.Page { dbconn obj = new dbconn(); protected void Page_Load(object sender, EventArgs e) { bindGrid(); } public static DataTable GetAllData() { DataTable alldata=new DataTable(); string dbcon = ConfigurationManager.AppSettings["connectioninfo"]; SqlConnection con = new SqlConnection(dbcon); con.Open(); SqlCommand cmd = new SqlCommand("GetData",con); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(alldata); return alldata; } protected void bindGrid() { GridView1.DataSource = GetAllData(); GridView1.DataBind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; bindGrid(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { TextBox uidtext = GridView1.Rows[e.RowIndex].FindControl("Textuid") as TextBox; TextBox pwdtext = GridView1.Rows[e.RowIndex].FindControl("txtpwd") as TextBox; string dbcon = ConfigurationManager.AppSettings["connectioninfo"]; SqlConnection con = new SqlConnection(dbcon); con.Open(); SqlCommand cmd = new SqlCommand("EditData", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", uidtext.Text); cmd.Parameters.AddWithValue("@password", pwdtext.Text); cmd.ExecuteNonQuery(); } we.config public class dbconn { public SqlConnection GetConnection() { SqlConnection con = default(SqlConnection); string connectioninfo = ConfigurationManager.AppSettings["connectionstring"]; con = new SqlConnection(connectioninfo); //if (con.State = ConnectionState.Closed) // con.Open(); return con; } public DataSet ExecuteDataset(string sql) { SqlConnection conn = GetConnection(); if (conn.State== ConnectionState.Closed) conn.Open(); DataSet ds=new DataSet(); SqlDataAdapter da = new SqlDataAdapter(sql,conn); da.Fill(ds); return (ds); } public void ExecuteCommand(string sql) { SqlConnection con = GetConnection(); if (con.State == ConnectionState.Closed) con.Open(); SqlCommand cmd = new SqlCommand(); cmd.ExecuteNonQuery(); } } Last edited by SANDHYAARORA; 25-08-09 at 02:22 AM.. |
| | |
![]() |
| Tags |
| edit , girdview , gridview edit |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can you edit data in the Repeater control | ShivaniX | ASP.NET | 0 | 25-05-08 12:50 AM |
| What is Mask Edit and why it is | ShivaniX | Visual Basics | 0 | 23-05-08 03:32 AM |
| QTP-How to select particular value from the combo box in the current page, which is entered in the previous page, edit box after parameterization? | Spoorthi | Testing Interview / Technical Questions | 1 | 29-10-07 12:50 PM |
| How to find out the length of the edit box through win runner? | Spoorthi | Testing Interview / Technical Questions | 0 | 13-02-07 12:10 PM |
| ADO.net - Why edit is not possible in repeater?? | preethisingh | vb / asp.net Interview / Technical Questions | 0 | 25-01-07 07:13 PM |
| More Interview Questions Here... |