c# - Gridview on Content page RowCommand does not fire - ViewState? -
the problem i'm having rowcommand of gridview not fire. i've read through millions of posts, , result think i'm more confused. so, if can see i've done wrong here, please point out.
i did ask similar question couple of weeks ago, using gridview nested in datalist , using 'include' siblings of entitydatasource display siblings, many side of relationship referral, it's fine display, figuring out edit update , delete nightmareish. i've tied simplify it, stopped in tracks because i'm losing controls somewhere in postbacks.
i have master page contentplaceholder:
<%@ master language="c#" autoeventwireup="true" codebehind="site.master.cs" inherits="homelessstudent.web.sitemasterpage" viewstatemode="inherit" enableviewstate="true" %> <asp:contentplaceholder id="contentplaceholderagent" runat="server"> </asp:contentplaceholder> on agent page-
<asp:content id="content" contentplaceholderid="contentplaceholderagent" runat="server"> <asp:panel id="siblingpanel" runat="server" viewstatemode="enabled" visible="true"> <asp:gridview id="siblinggridview" runat="server" cssclass="grid" autogeneratecolumns="false" datakeynames="id" showfooter="true" ondatabound="siblinggridview_databound" onrowediting="siblinggridview_rowediting" onrowupdating="siblinggridview_rowupdating" onrowcommand="siblinggridview_rowcommand" onrowdeleting="siblinggridview_rowdeleting" viewstatemode="enabled" clientidmode="static"> <columns> <asp:templatefield headertext="name" sortexpression="siblingname"> <edititemtemplate> <asp:textbox runat="server" text='<%# bind("siblingname") %>' id="textbox1"></asp:textbox> </edititemtemplate> <itemtemplate> <asp:label runat="server" text='<%# bind("siblingname") %>' id="label1"></asp:label> </itemtemplate> <footertemplate> <asp:textbox runat="server" id="newsiblingname" ></asp:textbox> </footertemplate> </asp:templatefield> <asp:templatefield headertext="edit" showheader="false"> <edititemtemplate> <asp:linkbutton runat="server" text="update" commandname="update" id="updatelinkbutton" ></asp:linkbutton> <asp:linkbutton runat="server" text="cancel" commandname="cancel" causesvalidation="false" id="linkbutton2"></asp:linkbutton> </edititemtemplate> <itemtemplate> <asp:linkbutton runat="server" text="edit" commandname="edit" id="editlinkbutton" clientidmode="static"></asp:linkbutton> </itemtemplate> <footertemplate> <asp:linkbutton runat="server" commandname="addnew" text="add" id="addnewlinkbutton"></asp:linkbutton> </footertemplate> </asp:templatefield> <asp:commandfield showdeletebutton="true" showheader="true" headertext="delete"></asp:commandfield> </columns> </asp:gridview> </asp:panel> code behind (binding data here because show siblings belong specific record, id (guid) record in querystring, maybe...
if (ispostback == false) { if (request.querystring["id"] == null) { if (session["studentid"] == null) { response.redirect("studentpage.aspx"); } else { referral = getmostrecentreferral((string)session["studentid"]); populateui(referral); } } else { referral = getthisreferral(request.querystring["id"]); populateui(referral); } } then, in populateui(referral)
some stuff... fillsiblinggrid(); string studentid = ((referral.studentid).tostring()).trim(); getselectedstudentdeatails(studentid); session["referralid"] = (guid)referral.id; and fill siblings grid-
private void fillsiblinggrid() { if (referral != null) { list<sibling> siblings = new list<sibling>(); using (homelessstudentdataentities db = new homelessstudentdataentities()) { siblings = (from s in db.siblings s.referralid == referral.id select s).tolist(); } if (siblings.count > 0) { siblinggridview.datasource = siblings; siblinggridview.databind(); } else { int totalcolumns = siblinggridview.rows[0].cells.count; siblinggridview.rows[0].cells.clear(); siblinggridview.rows[0].cells.add(new tablecell()); siblinggridview.rows[0].cells[0].columnspan = totalcolumns; siblinggridview.rows[0].cells[0].text = "no siblings found"; } } }
i faced similar problem. enabling grid view state resolved problem
Comments
Post a Comment