Some gridview rows' buttons do not work, some does ASP.Net C# -
i have project has problem , couldn't find reason why. use ajaxcontrol gridview display data come database.
each row when populated has delete , edit buttons. when delete clicked, should display confirmation pop up. when edit clicked, display modalpopupextender editing data.
some of buttons in rows (like 1st 15 rows) work, buttons of rows below not work. see picture
i use onrowdatabound sum values each employee , total of records
protected void gvdetails_onrowdatabound(object sender, gridviewroweventargs e) { (int rowindex = gvdetails.rows.count - 2; rowindex >= 0; rowindex--) { gridviewrow gvrow = gvdetails.rows[rowindex]; gridviewrow gvpreviousrow = gvdetails.rows[rowindex + 1]; (int cellcount = 0; cellcount < 2; //gvrow.cells.count cellcount++) { if (gvrow.cells[cellcount].text == gvpreviousrow.cells[cellcount].text) { if (gvpreviousrow.cells[cellcount].rowspan < 2) { gvrow.cells[cellcount].rowspan = 2; } else { gvrow.cells[cellcount].rowspan = gvpreviousrow.cells[cellcount].rowspan + 1; } gvpreviousrow.cells[cellcount].visible = false; } } } if (e.row.rowtype == datacontrolrowtype.datarow) { employeeno = convert.toint32(databinder.eval(e.row.dataitem, "employeeno").tostring()); double totalphp = convert.todouble(databinder.eval(e.row.dataitem, "php_amount").tostring()); double totalusd = convert.todouble(databinder.eval(e.row.dataitem, "usd_amount").tostring()); string adjtype = databinder.eval(e.row.dataitem, "adjtype").tostring(); if (adjtype == "income") { totalprice1 += totalphp; totalprice2 += totalusd; } else { totalprice1d += totalphp; totalprice2d += totalusd; } string snum = e.row.cells[4].text;//just changed index of cells based on requirements double sum; if (double.tryparse(snum, out sum)) { if (e.row.cells[7].text.tostring() == "income") { totali += sum; } else { totald += sum; } } string snum2 = e.row.cells[5].text;//just changed index of cells based on requirements double sum2; if (double.tryparse(snum2, out sum2)) { if (e.row.cells[7].text.tostring() == "income") { totali2 += sum2; } else { totald2 += sum2; } } } else if (e.row.rowtype == datacontrolrowtype.footer) { e.row.cells[3].style.add("padding", "0px"); e.row.cells[3].text = "<table align='right' style='width:194px;'><tr><td style='text-align:left;'>" + "total income:" + "</td></tr><tr><td style='text-align:left;'>" + "total deductions:" + "</td></tr></table>"; e.row.cells[3].horizontalalign = horizontalalign.left; e.row.cells[4].text = "<table style='width:100px;'><tr><td style='text-align:right; width:80px;'>" + totali.tostring("n") + "</td></tr><tr><td style='text-align:right;'>" + totald.tostring("n") + "</td></tr></table>"; e.row.cells[4].horizontalalign = horizontalalign.right; e.row.cells[5].text = "<table style='width:100px;'><tr><td style='text-align:right; width:80px;'>" + totali2.tostring("n") + "</td></tr><tr><td style='text-align:right;'>" + totald2.tostring("n") + "</td></tr></table>"; e.row.cells[5].horizontalalign = horizontalalign.right; } }
and use onrowcreated insert row footer each employee
protected void gvdetails_rowcreated(object sender, gridviewroweventargs e) { bool row = false; if ((employeeno > 0) && (databinder.eval(e.row.dataitem, "employeeno") != null)) { if (employeeno != convert.toint32(databinder.eval(e.row.dataitem, "employeeno").tostring())) row = true; } if ((employeeno > 0) && (databinder.eval(e.row.dataitem, "employeeno") == null)) { row = true; index = 0; } if (row) { gridview gridview1 = (gridview)sender; gridviewrow newtotalrow = new gridviewrow(0, 0, datacontrolrowtype.datarow, datacontrolrowstate.insert); newtotalrow.font.bold = true; newtotalrow.style.add("background-color", "#dbdbdb"); newtotalrow.style.add("color", "#444444"); newtotalrow.forecolor = system.drawing.color.white; tablecell headercell = new tablecell(); headercell = new tablecell(); headercell.horizontalalign = horizontalalign.left; headercell.text = ""; headercell.columnspan = 3; newtotalrow.cells.add(headercell); headercell = new tablecell(); headercell.horizontalalign = horizontalalign.left; headercell.style.add("padding", "0px"); headercell.text = "<table align='right' cellspacing='0' style='width:193px;'><tr><td style='text-align:left; width:122px;'>" + "total income:" + "</td></tr><tr><td style='text-align:left; width:200px;'>" + "total deductions:" + "</td></tr></table>"; newtotalrow.cells.add(headercell); headercell = new tablecell(); headercell.horizontalalign = horizontalalign.right; headercell.style.add("background-color", "#b4e7e1"); headercell.style.add("color", "#1c5e55"); headercell.style.add("padding", "0px"); headercell.text = "<table cellspacing='0' style='width:100px;'><tr><td style='text-align:right; width:80px;'>" + totalprice1.tostring("n") + "</td></tr><tr><td style='text-align:right;'>" + totalprice1d.tostring("n") + "</td></tr></table>"; newtotalrow.cells.add(headercell); headercell = new tablecell(); headercell.horizontalalign = horizontalalign.right; headercell.style.add("background-color", "#b5cbe7"); headercell.style.add("color", "#3d566f"); headercell.style.add("padding", "0px"); headercell.text = "<table cellspacing='0' style='width:100px;'><tr><td style='text-align:right; width:80px;'>" + totalprice2.tostring("n") + "</td></tr><tr><td style='text-align:right;'>" + totalprice2d.tostring("n") + "</td></tr></table>"; newtotalrow.cells.add(headercell); headercell = new tablecell(); headercell.horizontalalign = horizontalalign.right; headercell.text = ""; headercell.columnspan = 3; newtotalrow.cells.add(headercell); gridview1.controls[0].controls.addat(e.row.rowindex + index, newtotalrow); index++; totalprice1 = 0; totalprice1d = 0; totalprice2 = 0; totalprice2d = 0; } }
design code gridview
<asp:gridview id="gvdetails" cellpadding="2" runat="server" showheader="true" width="1130px" gridlines="both" autogeneratecolumns="false" cssclass="datagrid" emptydatatext= "no timekeeping transaction posted classification." datakeynames="employeeno" showfooter="true" onrowcreated="gvdetails_rowcreated" onrowdatabound="gvdetails_onrowdatabound"> <emptydatarowstyle backcolor="#e3eaeb" bordercolor="#1c5e55" horizontalalign="center" forecolor="#4b6c9e" /> <columns> <asp:boundfield datafield="empname" headertext="employee name" itemstyle-forecolor="#1c5e55" itemstyle-font-bold="true" sortexpression="empname" itemstyle-width="427px" headerstyle-horizontalalign="center" /> <asp:boundfield datafield="employeeno" headertext="employee no" itemstyle-width="341px" headerstyle-horizontalalign="center" /> <asp:boundfield datafield="adjustmentcode" headertext="adjustment code" itemstyle-width="417px" headerstyle-horizontalalign="center" /> <asp:boundfield datafield="adjustment" headertext="adjustment name" itemstyle-width="240px" headerstyle-horizontalalign="center" /> <asp:boundfield datafield="php_amount" headertext="php amount" itemstyle-backcolor="#d1f1ed" dataformatstring="{0:n2}" itemstyle-width="80px" itemstyle-horizontalalign="right" headerstyle-horizontalalign="center"/> <asp:boundfield datafield="usd_amount" headertext="usd amount" itemstyle-backcolor="#d1dff1" dataformatstring="{0:n2}" itemstyle-width="80px" itemstyle-horizontalalign="right" headerstyle-horizontalalign="center"/> <asp:boundfield datafield="taxablenote" headertext="taxable" itemstyle-width="80px" itemstyle-horizontalalign="center" headerstyle-horizontalalign="center" /> <asp:boundfield datafield="currencycode" headertext="currency" itemstyle-width="80px" itemstyle-horizontalalign="center" headerstyle-horizontalalign="center" /> <asp:boundfield datafield="adjtype" headertext="adjustment type" itemstyle-width="80px" itemstyle-horizontalalign="left" headerstyle-horizontalalign="center" /> <asp:templatefield itemstyle-width="16"> <itemtemplate> <asp:linkbutton id="lnkdelete" runat="server" cssclass="delete-item nooutline" width="16" height="16" tooltip="delete" commandargument='<%# bind("adjustmentno") %>' onclick="lnkdelete_click"></asp:linkbutton> </itemtemplate> </asp:templatefield> <asp:templatefield itemstyle-width="16"> <itemtemplate> <asp:linkbutton id="lnkedit" runat="server" cssclass="edit-item nooutline" width="16" height="16" tooltip="edit" commandargument='<%# bind("adjustmentno") %>' onclick="lnkedit_click"></asp:linkbutton> <asp:hiddenfield id="hdnnotes" runat="server" value='<%# bind("notes") %>' /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
this edit button click event
protected void lnkedit_click(object sender, eventargs e) { linkbutton lnksender = (linkbutton)sender; hdnadjustmentid.value = lnksender.commandargument.tostring(); gridviewrow gvrow = (gridviewrow)lnksender.namingcontainer; popuadjustment(); hdnnewedit.value = "edit"; divsearchnew.visible = false; lbledittitle.text = "edit payroll adjustment"; hiddenfield hdnnotes = (hiddenfield)gvrow.findcontrol("hdnnotes"); string payperiod = cutoffclass.getactivepayrollperiod(); txtfrom.text = payperiod.split('-')[0].tostring().trim(); txtto.text = payperiod.split('-')[1].tostring().trim(); lblsearchempname.text = gvrow.cells[0].text.tostring().trim(); lblsearchempno.text = gvrow.cells[1].text.tostring().trim(); txtnotes.text = hdnnotes.value; string adjcode = gvrow.cells[2].text.tostring().trim(); //drpadjcode.selectedvalue = string.compare(drpadjcode.selectedvalue, adkcpde, false); foreach (system.web.ui.webcontrols.listitem li in drpadjcode.items) { if (li.value.trim().toupper() == adjcode.trim().toupper()) { li.selected = true; } } string tax = gvrow.cells[6].text.tostring().trim(); foreach (system.web.ui.webcontrols.listitem li in drptaxable.items) { if (li.text.trim().toupper() == tax.toupper()) { li.selected = true; } else { li.selected = false; } } string adjtype = gvrow.cells[8].text.tostring().trim(); foreach (system.web.ui.webcontrols.listitem li in rdoadjtype.items) { if (li.text.trim().toupper() == adjtype.toupper()) { li.selected = true; } else { li.selected = false; } } string curr = gvrow.cells[7].text.tostring(); drpcurr.selectedvalue = curr; decimal amount = 0; if (curr == "php") { amount = convert.todecimal(gvrow.cells[4].text.tostring()); } else if (curr == "usd") { amount = convert.todecimal(gvrow.cells[5].text.tostring()); } txtamount.text = amount.tostring(); modalnew.show(); }
Comments
Post a Comment