Hi all. I am using the RowEditing for my databound GridView I am trying to access a DropDownList I am not able to get it in code even when I get the name spelled right - any ideas? It always returns nothing. I have even tried looping thru each cell to find
the control - it never finds it.
Dim row As GridViewRow = gvEditor.Rows(e.NewEditIndex)
Dim ddl As DropDownList = TryCast(row.FindControl("ddl"), DropDownList)
I also cannot cast my Entity item from the row.DataItem.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'here i am going to find dropdown
Dim DDLToolMaker As DropDownList = CType(e.Row.FindControl("DDLToolMaker"), DropDownList)
'here i am going to find textbox
Dim txtToolMakerEmpID As TextBox = CType(e.Row.FindControl("txtToolMakerEmpID"), TextBox)
'Populate DDLToolMaker
Dim gTitle As New EmpTitle
gTitle.EmpTitleGet(3)
DDLToolMaker.DataSource = gTitle.TitleData
DDLToolMaker.DataBind()
End If
End Sub
Good Luck
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
MadnessIsMin...
Member
1 Points
4 Posts
Unable to cast my controls.
Jan 26, 2013 06:47 PM|LINK
Hi all. I am using the RowEditing for my databound GridView I am trying to access a DropDownList I am not able to get it in code even when I get the name spelled right - any ideas? It always returns nothing. I have even tried looping thru each cell to find the control - it never finds it.
Dim ddl As DropDownList = TryCast(row.FindControl("ddl"), DropDownList)I also cannot cast my Entity item from the row.DataItem.
NadeemZee
Participant
942 Points
178 Posts
Re: Unable to cast my controls.
Jan 26, 2013 07:03 PM|LINK
use Row databound as in below code
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'here i am going to find dropdown Dim DDLToolMaker As DropDownList = CType(e.Row.FindControl("DDLToolMaker"), DropDownList) 'here i am going to find textbox Dim txtToolMakerEmpID As TextBox = CType(e.Row.FindControl("txtToolMakerEmpID"), TextBox) 'Populate DDLToolMaker Dim gTitle As New EmpTitle gTitle.EmpTitleGet(3) DDLToolMaker.DataSource = gTitle.TitleData DDLToolMaker.DataBind() End If End SubDo FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
oned_gk
All-Star
30979 Points
6338 Posts
Re: Unable to cast my controls.
Jan 26, 2013 08:38 PM|LINK