Datagrid inside Dropdown problem
-
Hi All, I have a datagrid, contains 3 columns.2 columns is boundcolumns and 1 is templatecolumn this template column contain Dropdown control.Fields like acct#,name type(Saving,Checking,Corporate etc.).Usally each row of dropdown show whatever the types avaible, but my case i want show 1st row is 2 values,2nd row is 3 values and 3rd row is 1 value.How can i do these situation.is there any way can implement.Please let me know. Thanks & Regards Rao
-
Hi All, I have a datagrid, contains 3 columns.2 columns is boundcolumns and 1 is templatecolumn this template column contain Dropdown control.Fields like acct#,name type(Saving,Checking,Corporate etc.).Usally each row of dropdown show whatever the types avaible, but my case i want show 1st row is 2 values,2nd row is 3 values and 3rd row is 1 value.How can i do these situation.is there any way can implement.Please let me know. Thanks & Regards Rao
Hi there, You simply create an event handler for the
ItemDataBound
event of the DataGrid, in the handler you can specify the datasource which is bound to the dropdownlist control based on the item index. The sample code goes like this:private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl = e.Item.FindControl("DropDownList1") as DropDownList;//Now you can sepcify the datasource bound to the dropdownlist //based on the e.Item.ItemIndex. .... }
}
-
Hi there, You simply create an event handler for the
ItemDataBound
event of the DataGrid, in the handler you can specify the datasource which is bound to the dropdownlist control based on the item index. The sample code goes like this:private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl = e.Item.FindControl("DropDownList1") as DropDownList;//Now you can sepcify the datasource bound to the dropdownlist //based on the e.Item.ItemIndex. .... }
}
Thank you, I need another solution for this grid.I want preselected database values to dropdown. Some rows show on the top of grid for example acctType is Checking and these rows diable it.This grid want do sorting also.Can i place single templatecoumn in grid multiple controls like 1 row is textbox,2nd row radiobutton ,3rd row dropdown etc.. How can i acheive this situations. Thanks & Regards Rao
-
Thank you, I need another solution for this grid.I want preselected database values to dropdown. Some rows show on the top of grid for example acctType is Checking and these rows diable it.This grid want do sorting also.Can i place single templatecoumn in grid multiple controls like 1 row is textbox,2nd row radiobutton ,3rd row dropdown etc.. How can i acheive this situations. Thanks & Regards Rao
Can we go with a single TemplateColumn like this?
asp:TemplateColumn
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
<asp:RadioButton Runat="server"></asp:RadioButton>
<asp:DropDownList Runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>At run time, depending on the index of the item, you can get and disable the controls which are not supposed to be in the row. Another way is to add the control dynamically. Also, you can think of the Repeater control with which you can be flexible in designing the layout, however, it does not support the sorting by default and you need to handle this issue on your own.
-
Can we go with a single TemplateColumn like this?
asp:TemplateColumn
<ItemTemplate>
<asp:TextBox Runat="server"></asp:TextBox>
<asp:RadioButton Runat="server"></asp:RadioButton>
<asp:DropDownList Runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>At run time, depending on the index of the item, you can get and disable the controls which are not supposed to be in the row. Another way is to add the control dynamically. Also, you can think of the Repeater control with which you can be flexible in designing the layout, however, it does not support the sorting by default and you need to handle this issue on your own.
-
Thank you. How can i show(Preselect)database value into dropdown. for example 1.Acct# 10 name smith john type Checking. 2.Acct#20 name roger longer type saving. above 2 rows first row preselected values is checking and 2nd saving etc. Thanks & Regards Rao