Sharepoint Gridview
- hey..
i m using gridview in my web part... everything is working fine.. but the update event not working..
edit n cancle n all event are working fine in my web part.. when i click update button nothing happen. postback occur bt nothing happend.
wats the error ?
thanks
All Replies
Hi Saad,
Can you please post your code so that we can verify where perhaps it goes wrong?
Karine Bosch- protected override void CreateChildControls()
{
this.gridvw.RowUpdating += new GridViewUpdateEventHandler(gridvw_RowUpdating);
this.gridvw.RowUpdated += new GridViewUpdatedEventHandler(gridvw_Rowupdated);
this.gridvw.RowEditing += new GridViewEditEventHandler(gridvw_RowEditing);
this.gridvw.PageIndexChanging += new GridViewPageEventHandler(gridvw_PageIndexChanging);
this.gridvw.RowCancelingEdit += new GridViewCancelEditEventHandler(gridvw_CancleRowEditing);
}
protected override void RenderContents(HtmlTextWriter writer)
{
making connection to database . connection datasource to grid n bind data perform in this tag..
}
protected void gridvw_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtname = ((TextBox)gridvw.Rows[e.RowIndex].FindControl("txtname"));
TextBox age = ((TextBox)gridvw.Rows[e.RowIndex].FindControl("age"));
TextBox desig = ((TextBox)gridvw.Rows[e.RowIndex].FindControl("desig"));
string update = "Update Testtable set Name='" + txtname + "',Age='" + age + "',Designation='" + desig + "' Where ID="
+ this.gridvw.DataKeys[e.RowIndex].Value;
SqlConnection con1 = new SqlConnection(conn1);
SqlCommand com = new SqlCommand(update, con1);
con1.Open();
com.ExecuteNonQuery();
con1.Close();
this.gridvw.EditIndex = -1;
this.gridvw.DataBind();
} Your code seems ok to me. When you place a breakpoint in the Update method and attach the Debugger to the SharePoint process and click the update button again, does the debugger hit your breakpoint?
Karine Bosch
no... its not hitting the breakpoint too .. and also not hitting breakpoint for any other event ...1) Where do you declare the gridvw variable? Is this a class level variable?
2) Where do you initialize this gridvw variable?
Karine Bosch- Most possible your code is not deployed correctly else it should hit that breakpoint.
do you debug with attached to w3p.exe?
kind regards,
Paul Keijzers
Check my website http://www.kbworks.nl or follow me on @KbWorks be sure to Check my KbWorks blog - have you attached your debugger to the server remotely? since you said all your other events are working fine, then the breakpoint should be hit.
When you click the update button, do the page do a postback or anything of that sort?
Never stop learning. - gridvw declare in class and initialize in createchildmthod
- how to attach w3p.exe process to debuger
- no m nt attch with to server remotely. yeah when i hit update a postback occur
- http://blogs.msdn.com/sharepoint/archive/2007/04/10/debugger-feature-for-sharepoint.aspx
Can you do a simple test, comment all the codes in your update event handler and Response.write something to see if it triggers. If it doesn't, your declaration or intialization might have problems. If it does, your SQL connection/queries might have problem :)
Never stop learning. - its not hitting the update event .. i found after debug it with w3p.exe process. and hitting all others event.
- Can you show the rendercontents block?
Never stop learning. - Hi Saad,
Can you please post the complete declaration of your gridview, including the properties you set?
Karine Bosch - protected override void RenderContents(HtmlTextWriter writer)
{
conn = new SqlConnection(conn1);
conn.Open();
comm = new SqlCommand(query1, conn);
new SqlDataAdapter(query1, conn1).Fill(this.datatab);
this.gridvw.DataSource = this.datatab;
this.gridvw.DataBind();
conn.Close();
his.gridvw.RenderControl(writer);
} - Hi Saad,
Can you please post the complete declaration of your gridview, including the properties you set?
Karine Bosch - like what Karine Bosch said, you might want to post the declaration of your gridview and see what's wrong with it.
Never stop learning. - public class SQL : System.Web.UI.WebControls.WebParts.WebPart
{
public SQL()
{
}
GridView gridvw;
protected override void CreateChildControls()
{this.Controls.Add(this.gridvw);
this.gridvw.AutoGenerateColumns = true;
this.gridvw.AllowPaging = true;
this.gridvw.HeaderStyle.Font.Bold=true;
this.gridvw.ShowHeader = true;
this.gridvw.ShowFooter = true;
this.gridvw.Visible = true;
this.gridvw.CellPadding = 2;
this.gridvw.CellSpacing = 2;
this.gridvw.GridLines = GridLines.Both;
this.gridvw.BorderColor = Color.Black;
this.gridvw.BorderWidth =2;
this.gridvw.AutoGenerateDeleteButton = true;
this.gridvw.AutoGenerateEditButton = true;
this.gridvw.AutoGenerateSelectButton = true;
this.gridvw.Width = 25;
this.gridvw.RowUpdating += new GridViewUpdateEventHandler(gridvw_RowUpdating);
this.gridvw.RowUpdated += new GridViewUpdatedEventHandler(gridvw_Rowupdated);
this.gridvw.RowEditing += new GridViewEditEventHandler(gridvw_RowEditing);
this.gridvw.PageIndexChanging += new GridViewPageEventHandler(gridvw_PageIndexChanging);
this.gridvw.RowCancelingEdit += new GridViewCancelEditEventHandler(gridvw_CancleRowEditing);
this.gridvw.RowDeleting += new GridViewDeleteEventHandler(gridvw_RowDelete);
} - hmm, where your update button come into the picture?
Never stop learning. - this.gridvw.AutoGenerateEditButton = true;
ohh ... when i click edit button it give 2 option cancel or update..... :S - since you are doing some test methods.. why don't you do a simple .NET app that can produce what is desired before bringing the codes over to webpart programming? Easier and faster to development this way, when you are trying to bring over to webpart dev, you will still go through some hiccups and learn along the way :)
Never stop learning. - allrite :) Thanks for the help .. :)
Hi Saad,
Does this mean your problem is solved? In that case can you mark the answer that helped you most?
Greetz,
Karine Bosch- not yet solved.. when it ll gt solved i ll mark it as answer
- its woking fine in web application.. but in web part its not hitting the event.. :(
Hi,Saad
As Karine Bosch said, your logic seems ok so please confirm if your event is really not hitting or your gridvw_Rowupdated method did not execute the database update logic.
Would you please also check your log file (Driver:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS) to see if you can get some clues there.
Best Regards,
-Aaron
- Can you do a simple test, in the update event, do a response.write("something") and see whether anything appears on your sharepoint. You also have to check whether you did a proper webpart deployment.. is the dll modified date latest?
Never stop learning. - yeh the updating event wasnt firing. on asp web its working fine bt on sharepoint web part its nt working.
Hi,Saad
As your desrioption on asp web its working fine
How did you test on your web app, also a webpart or webpart or usercontrol?
If all solutions did not work, would you please try other direction: create a webpart with usercontrol as a walkaround.
Hope this can hlep.
Best Regards,
-Aaron


