wsyeager Posted November 25, 2006 Posted November 25, 2006 (edited) I am using the Gridview control without a DataSource control. When I click on the Edit button, the page posts back and enters the following code: Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing Try Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex) [b]Dim ddlCustomerID As DropDownList = row.FindControl("ddlCustomerID")[/b] ddlCustomerID.DataSource = dstCustomers ddlCustomerID.SelectedIndex = ddlCustomerID.Items.IndexOf(ddlCustomerID.Items.FindByValue(dstCustomers.Tables(0).Rows(row.RowIndex).Item("CustomerID"))) ddlCustomerID.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Sub I cannot get an instance of the control in the above boldfaced code after passing thru that line during debugging. It has a value of Nothing. My html code is set up as follows (shortened for brevity) within the Gridview control: <asp:TemplateField HeaderText="CustomerID"> <EditItemTemplate> <asp:DropDownList ID="ddlCustomerID" runat="server" Text='<%# Bind("CustomerID") %>' DataValueField="CustomerID" DataTextField="ContactName"></asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblCustomerID" runat="server" Text='<%# Bind("CustomerID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> As you can see above, I have the name of the control defined in the above code in the EditItemTemplate. I am assuming that during the RowEditing event, I should be able to access the control in order to make it into a dropdownlist. During the RowUpdating event which is fired immediately after the RowEditing, I will get the SelectedValue. During non-editing, it is simply a Label control and grabs the value in the database for the CustomerID. It is only when I want to edit the row, that I cannot get an instance of the control. Can someone help me out here please? How can I get an instance of the control? Edited November 26, 2006 by PlausiblyDamp Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.