c# - SqlDataSource UpdateCommand parameters not changing -


i have formview updatebutton , sqldatasource below. updatebutton update sil table same values (the values @ first line of gridview), couldn't figure out why.

<asp:formview id="frm_benefit" runat="server" datakeynames="id" datasourceid="sds_benefits"             oniteminserted="frm_benefit_iteminserted" onitemupdated="frm_benefit_itemupdated">     <edititemtemplate>         <table class="formview">             <tr>                 <td>                     code:                 </td>                 <td>                     <asp:textbox id="codetextbox" runat="server" text='<%# bind("code") %>' />                 </td>             </tr>             <tr>                 <td>                     name:                 </td>                 <td>                     <asp:textbox id="nametextbox" runat="server" text='<%# bind("name") %>' />                 </td>             </tr>             <tr>                 <td>                     hrname:                 </td>                 <td>                     <asp:textbox id="hrnametextbox" runat="server" text='<%# bind("hrname") %>' />                 </td>             </tr>             <tr>                 <td>                     description:                 </td>                 <td>                     <asp:textbox id="descriptiontextbox" runat="server" text='<%# bind("description") %>'                         textmode="multiline" maxlength="200" />                 </td>             </tr>             <tr>                 <td>                     associated url:                 </td>                 <td>                     <asp:textbox id="urltextbox" runat="server" text='<%# bind("url") %>' maxlength="100" />                 </td>             </tr>             <tr>                 <td>                     benefittype:                 </td>                 <td>                     <asp:dropdownlist id="dropdownlist2" runat="server" datasourceid="sds_benefittypes"                         datatextfield="name" datavaluefield="id" selectedvalue='<%# bind("benefittypeid") %>'>                     </asp:dropdownlist>                 </td>             </tr>             <tr>                 <td>                     cost:                 </td>                 <td>                     <asp:textbox id="costtextbox" runat="server" text='<%# bind("cost") %>' />                 </td>             </tr>             <tr>                 <td>                     cost type:                 </td>                 <td>                     <asp:dropdownlist id="costtypedropdown" runat="server" datasourceid="sds_costtypes"                         datatextfield="name" datavaluefield="id" selectedvalue='<%# bind("costtypeid") %>'>                     </asp:dropdownlist>                 </td>             </tr>             <tr>                 <td>                     quantity type:                 </td>                 <td>                     <asp:dropdownlist id="quantitytypedropdown" runat="server" datasourceid="sds_quantitytypes"                         datatextfield="name" datavaluefield="id" selectedvalue='<%# bind("quantitytypeid") %>'>                     </asp:dropdownlist>                 </td>             </tr>             <tr>                 <td>                     quantity entry on add:                 </td>                 <td>                     <asp:checkbox id="quantityentryonaddcheckbox" runat="server" checked='<%# bind("quantityentryonadd") %>' />                 </td>             </tr>             <tr>                 <td>                     quantity entry on remove:                 </td>                 <td>                     <asp:checkbox id="quantityentryonremovecheckbox" runat="server" checked='<%# bind("quantityentryonremove") %>' />                 </td>             </tr>             <tr>                 <td>                     bonus ratio:                 </td>                 <td>                     <asp:textbox id="bonusratiotextbox" runat="server" text='<%# bind("bonusratio") %>'></asp:textbox>                 </td>             </tr>             <tr>                 <td>                     applyincometax:                 </td>                 <td>                     <asp:checkbox id="applyincometaxcheckbox" runat="server" checked='<%# bind("applyincometax") %>' />                 </td>             </tr>             <tr>                 <td>                     applystamptax:                 </td>                 <td>                     <asp:checkbox id="applystamptaxcheckbox" runat="server" checked='<%# bind("applystamptax") %>' />                 </td>             </tr>             <tr>                 <td class="style1">                     applysocialsecuritytax:                 </td>                 <td class="style1">                     <asp:checkbox id="applysocialsecuritytaxcheckbox" runat="server" checked='<%# bind("applysocialsecuritytax") %>' />                 </td>             </tr>             <tr>                 <td>                     applicable location:                 </td>                 <td>                     <asp:dropdownlist id="costtypedropdown1" runat="server" datasourceid="sds_locations"                         datatextfield="name" datavaluefield="id" selectedvalue='<%# bind("applicablelocationid") %>'>                     </asp:dropdownlist>                 </td>             </tr>             <tr>                 <td colspan="2">                     <asp:linkbutton id="updatebutton" runat="server" causesvalidation="true" commandname="update"                         text="update" style="display: none" />                     &nbsp;<asp:linkbutton id="updatecancelbutton" runat="server" causesvalidation="false"                         commandname="cancel" text="cancel" style="display: none" />                 </td>             </tr>         </table>     </edititemtemplate> </asp:formview>  <asp:sqldatasource id="sds_benefits" runat="server"  connectionstring="<%$ connectionstrings:connflexiblebenefitsdb %>"     selectcommand="select * [view_benefits]"      updatecommand="update [sil] set [code] = @code, [hrname] = @hrname [id] = @id">     <updateparameters>         <asp:parameter name="code" type="string" />         <asp:parameter name="hrname" type="string" />         <asp:parameter name="id" type="int32" />     </updateparameters>  </asp:sqldatasource> 

and gridview:

<asp:gridview id="grd_benefits" runat="server" autogeneratecolumns="false" datakeynames="id"     cssclass="gridtable" datasourceid="sds_benefits" onrowcommand="grd_benefits_rowcommand">     <rowstyle cssclass="gridrow" />     <footerstyle cssclass="gridfooter" />     <selectedrowstyle cssclass="gridselectedrow" />     <headerstyle cssclass="gridheader" />     <alternatingrowstyle cssclass="gridalternatingrow" />     <emptydatatemplate>         no records found.     </emptydatatemplate>     <columns>         <asp:boundfield datafield="code" headertext="code" sortexpression="code" />         <asp:boundfield datafield="hrname" headertext="hrname" sortexpression="hrname" />         <asp:templatefield headertext="benefit type" sortexpression="benefittype.name">             <itemtemplate>                 <asp:label id="label1" runat="server" text='<%# bind("benefittypename") %>'></asp:label>             </itemtemplate>         </asp:templatefield>         <asp:boundfield datafield="cost" headertext="cost" sortexpression="cost" />         <asp:templatefield headertext="cost type">             <itemtemplate>                 <asp:label id="label2" runat="server" text='<%# bind("costtypename") %>'></asp:label>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="quantity type">             <itemtemplate>                 <asp:label id="label3" runat="server" text='<%# bind("quantitytypename") %>'></asp:label>             </itemtemplate>         </asp:templatefield>         <asp:templatefield>             <itemtemplate>                 <asp:linkbutton id="lbselect" runat="server" causesvalidation="false" commandname="viewrecord"                     text="&lt;img border='0' alt='edit' src='../images/zoom.gif' /&gt;" commandargument='<%# container.dataitemindex %>'></asp:linkbutton>             </itemtemplate>         </asp:templatefield>         <asp:templatefield showheader="false">             <headertemplate>                 <asp:linkbutton id="lbinsert" runat="server" causesvalidation="false" commandname="newrecord"                     text="&lt;img border='0' alt='new' src='../images/new.gif'  /&gt;" commandargument='<%# container.dataitemindex %>'                     forecolor="white"></asp:linkbutton>             </headertemplate>             <itemtemplate>                 <asp:linkbutton id="lbedit" runat="server" causesvalidation="false" commandname="editrecord"                     text="&lt;img border='0' alt='edit' src='../images/edit.gif' /&gt;" commandargument='<%# container.dataitemindex %>'></asp:linkbutton>             </itemtemplate>         </asp:templatefield>     </columns> </asp:gridview> 

rowcommand:

    protected void grd_benefits_rowcommand(object sender, gridviewcommandeventargs e)     {                     if (e.commandname == "viewrecord")         {             grd_benefits.selectedindex = int.parse(e.commandargument.tostring());             frm_benefit.changemode(formviewmode.readonly);             page.clientscript.registerstartupscript(this.gettype(), "showformviewview", "<script type=\"text/javascript\">showformviewview();</script>");         }         else if (e.commandname == "newrecord")         {             frm_benefit.changemode(formviewmode.insert);             page.clientscript.registerstartupscript(this.gettype(), "showformviewinsert", "<script type=\"text/javascript\">showformviewinsert();</script>");         }         else if (e.commandname == "editrecord")         {             grd_benefits.selectedindex = int.parse(e.commandargument.tostring());             frm_benefit.changemode(formviewmode.edit);             page.clientscript.registerstartupscript(this.gettype(), "showformviewedit", "<script type=\"text/javascript\">showformviewedit();</script>");         }     } 

seeing markups , taking is, issue formview.

you have not set allowpaging="true" formview. every time formview displays, display first row of data records retrieved.

[ note form view displays 1 single record @ time ].

so every time selecting 'edit' in form view, editing first record ( indeed first row of gridview).

set allowpaging property true formview.

<asp:formview id="frm_benefit" runat="server" datakeynames="customerid"  datasourceid="sds_benefits" onitemupdated="frm_benefit_itemupdated"  allowpaging="true"> 

after using paging index, navigate record want change , edit seen below. enter image description here


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -