c# - Why does the expanded nested GridView automatically closes after opening it -
i have following gridview inside updatepanel:
<asp:gridview showheaderwhenempty="false" alternatingrowstyle-backcolor="#ebe9e9" autogeneratecolumns="false" onsorting="yourtasksgv_sorting" allowsorting="true" id="yourtasksgv" runat="server" clientidmode="static" emptydatatext="you have no tasks assigned you" onrowdatabound="yourtasksgv_rowdatabound" onrowcreated="yourtasksgv_rowcreated"> <columns> <asp:templatefield> <itemtemplate> <asp:imagebutton id="imgexpcol" imageurl="~/theimages/subtaskplus.png" runat="server" clientidmode="static" cssclass="imgexpcol" alternatetext="plus" commandargument='<%#eval("object") %>' oncommand="imgexpcol_command" /> <asp:panel id="pnlsubtasks" runat="server" cssclass="pnlsubtasks" clientidmode="static"> <asp:gridview id="gvsubtasks" runat="server" autogeneratecolumns="false" clientidmode="static"> <columns> <asp:boundfield datafield="task name" headertext="task name" /> <asp:boundfield datafield="due date" headertext="due date" /> </columns> </asp:gridview> </asp:panel> </itemtemplate> </asp:templatefield> <asp:hyperlinkfield target="_self" datanavigateurlfields="task detail" datatextfield="task name" datanavigateurlformatstring="" headertext="task detail" sortexpression="task name" itemstyle-cssclass="tasktablecolumn" /> <asp:templatefield> <itemtemplate> <asp:imagebutton imageurl="~/theimages/dependencies.png" cssclass="gvtaskdep btnshowdepend" runat="server" id="btnshowdepend" oncommand="btnshowdepend_command" commandname="taskdepend" alternatetext='<%#eval("object") + "," + eval("fk") %>' commandargument='<%#eval("object") + "," + eval("fk") %>' tooltip="click view dependencies" /> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="service" headertext="service" sortexpression="service" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="status" headertext="status" sortexpression="status" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="due date" headertext="due" sortexpression="due date" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="owner" headertext="owner" sortexpression="owner" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="client" headertext="client" sortexpression="client" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="site" headertext="site" sortexpression="site" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="practice" headertext="practice" sortexpression="practice" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="provider" headertext="provider" sortexpression="provider" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="roles" headertext="roles" sortexpression="roles" itemstyle-cssclass="tasktablecolumn" /> <asp:boundfield datafield="object" headertext="object" sortexpression="object" itemstyle-cssclass="hidetag" headerstyle-cssclass="hidetag" /> <asp:boundfield datafield="fk" headertext="fk" sortexpression="object" itemstyle-cssclass="hidetag" headerstyle-cssclass="hidetag" /> </columns> </asp:gridview>
jquery:
$(function () { $("body").on('click', "input[alt='plus']", function () { alert("test"); $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>") $(this).attr("src", "../theimages/subtaskminus.png"); $(this).attr("alt", "minus"); }); $("body").on('click', "input[alt='minus']", function () { alert("test2"); $(this).attr("src", "../theimages/subtaskplus.png"); $(this).attr("alt", "plus"); $(this).closest("tr").next().remove(); }); });
code-behind:
protected void yourtasksgv_rowdatabound(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.datarow) { gridview gvorders = e.row.findcontrol("gvsubtasks") gridview; gvorders.datasource = runsubtaskquery(); gvorders.databind(); tasksupdatepanel.update(); //begin: figure out row should have plus icon #region list<string> lstsubtask = new list<string>(); string strquerysubtasks = @"select ct.objectid 'object id' ,attr2888 'subtask name' ,m.memo 'subtask details' ,attr2890 'status' ,st.fk2898 'parent task object id' ,ct.attr2739 'parent task name' hsi.rmobjectinstance1244 st inner join hsi.rmmemo m on st.mk2889 = m.memoid inner join hsi.rmobjectinstance1224 ct on st.fk2898 = ct.objectid st.activestatus = 0 , ct.activestatus = 0 , ct.objectid = '" + objectid + "'"; using (sqlconnection scsubtask = new sqlconnection(connstring)) { sqlcommand cmd = new sqlcommand(strquerysubtasks, scsubtask); scsubtask.open(); sqldatareader sdrst = cmd.executereader(); if (!string.isnullorempty(objectid) && objectid != " ") { while (sdrst.read()) { lstsubtask.add(sdrst[0].tostring().trimend()); } } sdrst.close(); } #endregion if (lstsubtask.count == 0) { imagebutton ibexp = e.row.findcontrol("imgexpcol") imagebutton; if (ibexp != null) { ibexp.visible = false; } //hide plus button }//end: figure out row should have plus icon } }
the issue having is, when click plus button expand existing row show nested gridview, opens collapses after few seconds , doesn't wait me close manually.
how fix it?
try this..
$("[src*=plus]").live("click", function () { $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>") $(this).attr("src", "../theimages/subtaskplus.png"); }); $("[src*=minus]").live("click", function () { $(this).attr("src", "../theimages/subtaskminus.png""); $(this).closest("tr").next().remove(); });
i using above javascript expand , collapse gridviews within gridviews. works you.
Comments
Post a Comment