views:

1305

answers:

1

hi guys, I am using following code in rowdatabound fn.

Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

        If e.Row.RowType = DataControlRowType.Footer Then
            Dim ddlItem As DropDownList = CType(e.Row.FindControl("ddlFProjectLevels"), DropDownList)
            If ddlItem IsNot Nothing Then
                ddlItem.DataSource = objMileStone.GetProjectLevels()
                ddlItem.DataValueField = "MileStoneID"
                ddlItem.DataTextField = "Name"
                ddlItem.DataBind()
            End If
        End If
        If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.RowState = DataControlRowState.Edit Then
                Dim ddlEProjectLevels As DropDownList = CType(e.Row.FindControl("ddlEProjectLevels"), DropDownList)
                ddlEProjectLevels.DataSource = objMileStone.GetProjectLevels()
                ddlEProjectLevels.DataValueField = "MileStoneID"
                ddlEProjectLevels.DataTextField = "Name"
                ddlEProjectLevels.DataBind()
                ddlEProjectLevels.SelectedValue = milestoneid
            End If
        End If


    End Sub

ddlEProjectLevels is dropdownlist in edititemtemplate.Whwn i click edit in 1st row ddlEProjectLevels gets loaded with data from database.But in 2nd row dropdownlist does not contain values.Again in 3rd it gets loaded from db.Means in alternate rows,when i click edit dropdownlist(ddlEProjectLevels) doesnot load values.Can anybody help?

+2  A: 

This issue is somewhat confusing compared to other controls and applies to GridView and DetailsView controls. You'll need to check the RowState enumeration using bitwise logic since an item may have a state of Alternate or Edit.

So instead of:

If e.Row.RowState = DataControlRowState.Edit Then

Try:

If (e.Row.RowState And DataControlRowState.Edit) > 0 Then

For more info check out the DataControlRowState Enumeration page.

Ahmad Mageed
It worked.Thanks a lot.
Great! No problem :)
Ahmad Mageed
burntsugar