jeffreyjseaman
asked on
Find Drop Down List Control in ItemTemplate
I have a GridView with a Template Field that has a dropdownlist in the column.
I need to be able to communicate with the dropdownlist. But when I run the code to find the control the results I get is ControlValue = Nothing.
I need to be able to communicate with the dropdownlist. But when I run the code to find the control the results I get is ControlValue = Nothing.
pagename.aspx
<asp:TemplateField HeaderText="Column" SortExpression="Column">
<ItemTemplate>
<asp:DropDownList ID="ddlColumn" runat="server" AutoPostBack="true"
></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
pagename.aspx.vb
Dim ddlTypeOf As DropDownList = CType(FindControl("ddlColumn"), DropDownList)
hi
try this code in OnRowDataBound Method.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx
just put e.Row.FindControl(....
try this code in OnRowDataBound Method.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx
just put e.Row.FindControl(....
Hi jeffreyjseaman,
In the previous mail i forgot to add the row to gridview.
You will have to give the row also
like
Dim ddlTypeOf As DropDownList = CType(GridView1.Row(0).Fin dControl(" ddlColumn" ), DropDownList)
change the row position according to ur requirement.
If in a RowDataBound Event u can just give
Dim ddlTypeOf As DropDownList = CType(e.Row.FindControl("d dlColumn") , DropDownList)
If in a RowCommand event, u will have to find the rowindex from where the command was called.
In the previous mail i forgot to add the row to gridview.
You will have to give the row also
like
Dim ddlTypeOf As DropDownList = CType(GridView1.Row(0).Fin
change the row position according to ur requirement.
If in a RowDataBound Event u can just give
Dim ddlTypeOf As DropDownList = CType(e.Row.FindControl("d
If in a RowCommand event, u will have to find the rowindex from where the command was called.
Use GridView's SelectedRow object. Which will give you selected row object and you can find ddlColumn combo in that row.
Dim ddlTypeOf As DropDownList = CType(Use GridView.SelectedRow.FindC ontrol("dd lColumn"), DropDownList)
Dim ddlTypeOf As DropDownList = CType(Use GridView.SelectedRow.FindC
ASKER
I've used the following but it's coming up with NOTHING
Dim ddlTypeOf As DropDownList = CType(e.Row.FindControl("c boType"), DropDownList)
But if I do the following; it recognizes the control but it doesn't populate the dropdownlist.
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddlTypeOf As DropDownList = CType(e.Row.FindControl("c boType"), DropDownList)
End If
Dim ddlTypeOf As DropDownList = CType(e.Row.FindControl("c
But if I do the following; it recognizes the control but it doesn't populate the dropdownlist.
If e.Row.RowType = DataControlRowType.DataRow
Dim ddlTypeOf As DropDownList = CType(e.Row.FindControl("c
End If
what do u want to do? do u want to populate data to the dropdown?
ASKER
Rajeeshmca,
That's correct. I'm executing a stored procedure by sending it parameters. When it completes it's section I want to databhind to that dropdownlist.
If this DropDownList wasn't in the grid it works perfectly. But it needs to be in a grid.
That's correct. I'm executing a stored procedure by sending it parameters. When it completes it's section I want to databhind to that dropdownlist.
If this DropDownList wasn't in the grid it works perfectly. But it needs to be in a grid.
Call a function within the dropdown control using the Datasource property like
<ItemTemplate>
<asp:DropDownList ID="ddl_Region" CssClass="reqFields" runat="server" DataSource='<%# fillRegionDropDown() %>' DataTextField="Descr" DataValueField="RegionId" SelectedValue='<%# Bind("RegionId") %>' AppendDataBoundItems="True " >
</asp:DropDownList>
</ItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddl_Region" CssClass="reqFields" runat="server" DataSource='<%# fillRegionDropDown() %>' DataTextField="Descr" DataValueField="RegionId" SelectedValue='<%# Bind("RegionId") %>' AppendDataBoundItems="True
</asp:DropDownList>
</ItemTemplate>
ASKER
Rajeeshmca,
What do you mean be call a function? where in SQL? You have a DataSource. Where is the Data Source coming from?
What do you mean be call a function? where in SQL? You have a DataSource. Where is the Data Source coming from?
Hi jeffreyjseaman,
Call a user defined function in the code behind (cs Page).... this function will fetch the data from the database...
Call a user defined function in the code behind (cs Page).... this function will fetch the data from the database...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Under which event do you want to find the control.
Instead of giving just FindControl, give it as GridView1.FindControl like
Dim ddlTypeOf As DropDownList = CType(GridView1.FindContro
Change the name of the gridview according to ur requirement