Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ASP.code
C#
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="624px" CssClass="grid" 
            AllowPaging="True" AllowSorting="True" BackColor="White"  OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
            BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" PageSize = "5" 
            OnRowUpdating="GridView1_RowUpdating" DataKeyNames="id">
            
                <columns>
                <asp:TemplateField>
                <itemtemplate>
                <asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" />
                </itemtemplate>
                
                 <asp:TemplateField HeaderText="Username">
                    <edititemtemplate>
                    <asp:TextBox ID="lbleditusr" runat="server" Text='<%#Eval("username") %>'/>
                    </edititemtemplate>
                    <itemtemplate>
                    <asp:Label ID="lblitemUsr" runat="server" Text='<%#Eval("username") %>'/>
                    </itemtemplate>
                    <footertemplate>
                    <asp:TextBox ID="txtftrusrname" runat="server"/>
                    <asp:RequiredFieldValidator ID="rfvusername" runat="server" ControlToValidate="txtftrusrname" Text="*" ValidationGroup="validaiton"/>
                    </footertemplate>
                    

                    <asp:TemplateField  HeaderText="Password">
                         <edititemtemplate>
                             <asp:TextBox ID="txtpass" runat="server" Text='<%#Eval("password") %>'/>
                         </edititemtemplate>
                         <itemtemplate>
                             <asp:Label ID="lblpass" runat="server" Text='<%#Eval("password") %>'/>
                         </itemtemplate>
                         <footertemplate>
                          <asp:TextBox ID="txtftrpass" runat="server"/>
                          <asp:RequiredFieldValidator ID="rfvcity" runat="server" ControlToValidate="txtftrpass" Text="*" ValidationGroup="validaiton"/>
                         </footertemplate>
                     
                    <asp:TemplateField HeaderText="Mail">
                         <edititemtemplate>
                             <asp:TextBox ID="txtmail" runat="server" Text='<%#Eval("mail") %>'/>
                         </edititemtemplate>
                         <itemtemplate>
                             <asp:Label ID="lblmail" runat="server" Text='<%#Eval("mail") %>'/>
                         </itemtemplate>
                         <footertemplate>
                             <asp:TextBox ID="txtftrmail" runat="server"/>
                        <asp:RequiredFieldValidator ID="rfvdesignation" runat="server" ControlToValidate="txtftrmail" Text="*" ValidationGroup="validaiton"/>
                         </footertemplate>
                     
                    <asp:TemplateField>
                    <edititemtemplate>
                    <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/gridviewimage/update.jpg" ToolTip="Update" Height="20px" Width="20px" />
                    <asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/gridviewimage/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
                    </edititemtemplate>
                    <itemtemplate>
                    <asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="~/gridviewimage/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" />
                    <asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="~/gridviewimage/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
                    </itemtemplate>
                    <footertemplate>
                    <asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="~/gridviewimage/AddNewitem.jpg" CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
                    </footertemplate>
                                
            </columns>
            <footerstyle backcolor="White" forecolor="#000066" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
            <pagerstyle backcolor="White" forecolor="#000066" horizontalalign="Left" />
            <rowstyle forecolor="#000066" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <sortedascendingcellstyle backcolor="#F1F1F1" />
            <sortedascendingheaderstyle backcolor="#007DBB" />
            <sorteddescendingcellstyle backcolor="#CAC9C9" />
            <sorteddescendingheaderstyle backcolor="#00547E" />





C#
C#
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
   {
       GridView1.EditIndex = e.NewEditIndex;
       FillGrid();
   }
   protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());

       TextBox lbleditusr = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lbleditusr");
       TextBox txtpass = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpass");
       TextBox txtmail = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmail");

       cmd = new SqlCommand("update getezee set username=@username,password=@password,mail=@mail where id=@id", con);
       cmd.Parameters.AddWithValue("@username", lbleditusr.Text);
       cmd.Parameters.AddWithValue("@password", txtpass.Text);
       cmd.Parameters.AddWithValue("@mail", txtmail.Text);
       cmd.Parameters.AddWithValue("@id", id);
       con.Open();
       cmd.ExecuteNonQuery();
       con.Close();
       FillGrid();

   }
Posted
Updated 7-Oct-14 0:39am
v4
Comments
ZurdoDev 30-Sep-14 7:36am    
Are you sure this code gave that error?
Member 10918596 30-Sep-14 7:44am    
yes
ZurdoDev 30-Sep-14 7:46am    
Just debug it. lbleditusr is likely null or some other issue.
Member 10918596 30-Sep-14 7:47am    
when i run this error only came
ZurdoDev 30-Sep-14 7:49am    
It is very easy to debug. Put a breakpoint and see what the value is. The value must be null for you to be getting that error.

1 solution

Your Parameter must evaluate a value
cmd.Parameters.AddWithValue("@username", lbleditusr.Text);


in this case lbledituser.Text should not evaluate to null.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900