Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by PlausiblyDamp

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...