Advertisement

02.01.2006 at 05:52AM PST, ID: 21718425
[x]
Attachment Details

Choose value in DropDown list on Edit command in GridView

Asked by iboutchkine in Programming for ASP.NET

Tags: gridview, dropdownlist, edit, list

I have a GridView bound to the dataset. When I click Edit button I have a drop down list bound to the different database table. Let's say in column 3 in normal mode I have Label that has value 3. When I switch to the edit mode I have the drop down in the column 3 with values 1,2,3,4,5. By default the dropdown will show the top value i.e. 1. If I click update even without selecting something in the drop down , the value of the label will be changed to 1.
Somehow when I switch to the edit mode I have to select the value in the drop down equal to the value that I have currently in the label.
I was trying the RowCommand event to enter the following code

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Edit" Then
            Dim index As Integer = GridView1.EditIndex
            Dim row As GridViewRow = GridView1.Rows(index)
            Dim dd As DropDownList = CType(row.Cells(3).FindControl("ddTAType"), DropDownList)
            dd.Text = ......
        End If
    End Sub

The problem is n the line
            Dim dd As DropDownList = CType(row.Cells(3).FindControl("ddTAType"), DropDownList)

dd comes up as Nothing and I cannot assin the value.

The same is in the  RowEditing event.

The code

        Dim index As Integer = GridView1.EditIndex
        Dim row As GridViewRow = GridView1.Rows(index)


        Dim dd As DropDownList = CType(row.Cells(3).FindControl("ddTAType"), DropDownList)

works fine in the RowUpdated event.

I need to enter value of the label to the dropdown list. Does somebody have any clue?
Thank youStart Free Trial
[+][-]02.01.2006 at 05:56AM PST, ID: 15843108

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Programming for ASP.NET
Tags: gridview, dropdownlist, edit, list
Sign Up Now!
Solution Provided By: scolja
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.01.2006 at 06:14AM PST, ID: 15843240

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32