c# - Gridview postback datasource persistance -


i have grid data bound generic list. edit , need persist changes of, db.

the problem when hit submit button postback. , sets data source of gridview null.

i've tried storing data source in view state viewstate["data"] works great data isn't being updated in viewstate when changes made on grid.

any ideas?

here code gridview:

<asp:gridview id="dgmerchantconfiguration" runat="server"      autogeneratecolumns="false"     causesvalidation="false" custompagercssclass="" headerheight="30px" numberofpagesheight="15px"     numberofpageswidth="40px" pagerheight="15px" pagerwidth="40px" showdatagridcustompaging="none"     sortheight="15px" sortwidth="70px" backcolor="white" bordercolor="#999999" borderwidth="1px"     cellpadding="1" font-size="smaller" gridlines="vertical" width="100%"      onrowdatabound="dgmerchantconfiguration_rowdatabound" viewstatemode="enabled" enableviewstate="false">     <selectedrowstyle font-bold="true" forecolor="white" backcolor="#f80000"></selectedrowstyle>     <alternatingrowstyle backcolor="gainsboro"></alternatingrowstyle>     <rowstyle forecolor="black" backcolor="#eeeeee"></rowstyle>     <headerstyle font-bold="true" forecolor="white" backcolor="#bd0000" horizontalalign="center"></headerstyle>     <footerstyle forecolor="black" backcolor="#cccccc"></footerstyle>     <columns>         <asp:boundfield datafield="id" headertext="id">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>         </asp:boundfield>          <asp:boundfield datafield="commissiontype" headertext="commission type">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>         </asp:boundfield>         <asp:templatefield headertext="select">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:checkbox id="chkselect" runat="server" checked='<%# bind("selected") %>' oncheckedchanged="chkselect_checkedchanged" autopostback="true" />             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="override">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:checkbox id="chkoverride" runat="server" checked='<%# bind("default") %>' oncheckedchanged="chkoverride_checkedchanged" autopostback="true" />             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="comission structure">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:dropdownlist id="drpcommissionstructure" runat="server" width="200px" onselectedindexchanged="drpcommissionstructure_selectedindexchanged" autopostback="true"></asp:dropdownlist>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="min">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtmin" runat="server" width="50px" text='<%# bind("min") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="max">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtmax" runat="server" width="50px" text='<%# bind("max") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="fixed">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtfixed" runat="server" width="50px" text='<%# bind("fixed") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="cost per unit">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtcostperunit" runat="server" width="50px" text='<%# bind("costperunit") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="unit value">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtunitvalue" runat="server" width="50px" text='<%# bind("unitvalue") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="excluded amount">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtexclamount" runat="server" width="50px" text='<%# bind("excludedamount") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="percentage">             <headerstyle horizontalalign="center" cssclass="normalbold"></headerstyle>             <itemstyle horizontalalign="center" cssclass="normal"></itemstyle>             <itemtemplate>                 <asp:textbox id="txtpercentage" runat="server" width="50px" text='<%# bind("percentage") %>'></asp:textbox>             </itemtemplate>         </asp:templatefield>     </columns> </asp:gridview> 

and how data source set:

protected void ddlmerchants_selectedindexchanged(object sender, eventargs e) {     // load selected businesses config db     var t = client.getmerchantcommissionstructure(new getmerchantcommissionstructurerequest() { merchantid = int32.parse(ddlmerchants.selecteditem.value) });      viewstate["data"] = t.configurations;     dgmerchantconfiguration.datasource = t.configurations;     dgmerchantconfiguration.databind(); } 

thanks in advance!


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -