i have been developing webpage uses n number of dropdownlists binding dynamically inside gridview. want perform operations based on dropdownlist's selectedindexchanged event. had done , working good, when changed dropdownlist on second time postback not calls event.
you can see code here
<%@ page language="c#" autoeventwireup="true" codefile="griddropdowntest.aspx.cs" inherits="griddropdowntest" %><!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <asp:gridview id="gridledgedetails" runat="server" onrowdatabound="onrowdatabound" ondatabound="gridledgedetails_databound"> </asp:gridview> </div> </form></body></html> using system; using system.web.ui; using system.web.ui.webcontrols; using system.data; public partial class griddropdowntest : system.web.ui.page { protected void page_load(object sender, eventargs e) { databind(); } public void databind() { datatable dt = new datatable(); dt.columns.add("mode"); dt.rows.add(""); dt.rows.add(""); gridledgedetails.datasource = dt; gridledgedetails.databind(); } protected void onrowdatabound(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.datarow) { dropdownlist ddlmode = new dropdownlist(); ddlmode.width = 90; ddlmode.attributes.add("style", "background-color:#ff6600;"); ddlmode.items.add("regular"); ddlmode.items.add("monthwise"); ddlmode.selectedindexchanged += new eventhandler(ddlmode_indexchanged); ddlmode.autopostback = true; ddlmode.id = "ddlmode_"; e.row.cells[0].controls.add(ddlmode); } } protected void gridledgedetails_databound(object sender, eventargs e) { } protected void ddlmode_indexchanged(object sender, eventargs e) { string uid = this.page.request.params.get("__eventtarget"); if (uid != null && uid.contains("ddlmode_")) { string[] values = uid.split('$'); string row = values[1].replace("ctl", ""); control ctrl = page.findcontrol(uid); dropdownlist ddl = (dropdownlist)ctrl; if (ddl.selectedindex == 1) { } } } }
for need take , bind dropdownlist again in page_preinit page method.
for example....
protected void page_preinit(object sender, eventargs e)
{
// here need build gridview again.
// state retain same......
}
Comments
Post a Comment