How to access a template column in a datagrid control

I have a DataGrid control on a web form with a template column. How can I access the dropdownlist column "ddlusertype" from my c# code? I need to bind it with a DataTable. Please help, thanks!

Here is my code
<Columns>
<asp:BoundColumn DataField="rolName" HeaderText="User Type"></asp:BoundColumn>
<asp:BoundColumn DataField="rolDescription" HeaderText="Description"></asp:BoundColumn>
<asp:BoundColumn DataField="gtyAbbr" HeaderText="Client Type"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Client Type">
<ItemTemplate>
<asp:dropdownlist ID="ddlusertype" enabled="true" DataTextField="gtyAbbr" DataValueField="gtyID" Runat="server"></asp:dropdownlist>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
0
youpingli
4/5/2004 8:44:05 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
617 Views

Similar Articles

[PageSpeed] 42

Handle ItemDataBound for the grid. You can access the dropdown there to bind it. In the ItemDataBound event handler, you need to confirm you're on the right type of item/row. 

For example, there's no listbox in the header row.
  Sub myGrid_ItemDataBound(s As System.Object, e As DataGridItemEventArgs) Handles MyGrid.ItemDataBound

Select e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim lb As ListBox
lb = CType(e.Item.FindControl("rfq_listbox"), ListBox)
lb.DataSource = binddata.GetData()
lb.DataBind()
lb.Items.FindByText(e.Item.DataItem("colNameWithSelectedValue")).Selected = true
End Select
End Sub

Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
4/5/2004 9:18:11 PM
Reply: