Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get edit template control value in Gridview

Status
Not open for further replies.

lisat76

Programmer
Sep 25, 2007
89
US
I have a gridview that has two edit item templates which have controls textbox and a label I want to get the value of the controls when I update the gridview and add that to the update parameters. I keep getting object reference not set to an instance of an object for the label and the textbox. I cannot figure this out.
I can't believe this has stumped me as I know I have done it before and it is very simple I must be over looking something.
here is my vb
Code:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
 Handles GridView1.RowUpdating
      
	  Dim varSSN  As Integer = CType(GridView1.FindControl("lblSSNed"), TextBox).Text 'GridView1.SelectedRow.Cells(1).Text
        Dim varEmpID  As Integer = CType(GridView1.FindControl("txtEmpID"), TextBox).Text
 
        sdsMissedImports.UpdateParameters.Item("SSN").DefaultValue = varSSN
        sdsMissedImports.UpdateParameters.Item("EmpID").DefaultValue = varEmpID
        sdsMissedImports.Update()

    End Sub

here is my gridview
Code:
<asp:GridView ID="GridView1" runat="server"          <Columns>
            <asp:CommandField ShowEditButton="True" />
           
                <asp:TemplateField >
                <EditItemTemplate>
               <p> Enter This employees Employee ID and Click update to 
               <br />   import all of this employees missed imports into Health/Dental Etc Databases. 
               Please Verify you have the correct EMPID before doing this</p>
                <asp:Textbox id="txtEmpID" runat="Server" />
                <asp:RequiredFieldValidator ID="reQEmpID" runat="server" ControlToValidate="txtEmpID" ErrorMessage="EmpID is Required" />
                <asp:RegularExpressionValidator runat="server" ID="RegexEmpID" ErrorMessage="Please Enter EMPID no Letters & Max of 11 numbers" ControlToValidate="txtEmpID" Font-Bold="True"  
                        ValidationExpression="(\d{1,11})" Display="None"></asp:RegularExpressionValidator>
                        <ajaxToolkit:ValidatorCalloutExtender ID="EmpCallOut" runat="server"  
                        TargetControlID="RegexEmpID"  Enabled="True"></ajaxToolkit:ValidatorCalloutExtender>
                </EditItemTemplate>
                </asp:TemplateField>
          <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
            <asp:TemplateField HeaderText="SSN" SortExpression="SSN">
                <EditItemTemplate>
                    <asp:Label ID="lblSSNed" runat="server" Text='<%# Eval("SSN") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblSSN" runat="server" Text='<%# Bind("SSN") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
</columns>
</gridview>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top