0
Protected void Update(object sender, GridViewCommandEventsArg e)
{
if(e.CommandName == "Change")
{
        int index = GridViewemp.EditIndex;
        GridViewRow grid = GridViewemp.Rows[index];

        TextBox salary = (TextBox)GridViewemp.FindControl("TextBoxsalary");

         sqlcon.Open();
         string query = "Update Employee set Salary="+salary.Text+"where EmpID     ="+GridViewemp.SelectedDataKey.Value.ToString();
         sqlcom = new SqlCommand(query, sqlcon);
         sqlcom.ExecuteNonQuery();
         sqlcon.Close();
}

}

I am getting the error Error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.

Please help me to get the value from TextBoxsalary

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by asha2009
0

I think there should be a miss match off datatype, if your Empid is a string type so it must be in single quote

string query = "Update Employee set Salary="+salary.Text+"where EmpID     ='"+GridViewemp.SelectedDataKey.Value.ToString()+"'";

I hope it will help you

0

Thanks for the reply prvnkmr194 but my EmpID is not a string. I forgot to mention that this grid is in a panel.

0

Could you tell us which line is throwing the exception so we don't have to validate that every object in your code exists?

0

line 8.. the error message is in the first post. textboxsalary does exist

0

Textbox is in the edit template of the gridview

<EditItemTemplate>
                     <asp:Label ID="Labelfname" runat="server" Text='<%#Eval("Fname") %>'></asp:Label>
                        &nbsp;
                        <asp:Label ID="Labelsurname" runat="server" Text='<%#Eval("Surname") %>'></asp:Label>
                        &nbsp; appointed&nbsp;
                        <asp:Label ID="Labelappoint" runat="server" 
                            Text='<%# Eval("Appointmentdate") %>'></asp:Label>
                        <br />
                        change salary&nbsp;
                        <asp:TextBox ID="TextBoxsalary" runat="server" Text='<%#Bind("Salary") %>'></asp:TextBox>
                        &nbsp;<asp:LinkButton ID="LinkButtonupdate" runat="server" CommandName="Update">Update</asp:LinkButton>
                        &nbsp;
                        <asp:LinkButton ID="LinkButtoncancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                    </EditItemTemplate>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.