By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

Different Server Controls in DataGrid

P: n/a
Can anyone provide any advice or article on creating DataGrid and bind it with data but for every column of data, there may be different Server Controls. To make it clear, let say i want bind 1 field in one DataGrid, but for the only field i want to bind, i may have Label control from rows 1 - 5 and , i want to bind checkboxes to rows from row 6 - 8 and i want to bind again the label controls from row 9 - 11. Can i do that in DAtagrid in ASP.NET ???? Thanks you very much
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
It's possible but could be very costly

You have to Handle the ItemDataBound method of the datagrid. One of the parameters of the method is the Item row of the datagrid. You can use it to get a handle on the cell or column which you want for that row and dynamically add your control

For example

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e

switch(condition) //your conditio

case "DropDown": //your matc
DropDownList ddl = new DropDownList()
e.Item.Cells[yourcellindex].Controls.Add(ddl)
break
case "TextBox": //your matc
TextBox txt = new TextBox()
e.Item.Cells[yourcellindex].Controls.Add(txt)
break
default
Label lbl = new Label()
e.Item.Cells[yourcellindex].Controls.Add(lbl)
break

HTH
Suresh

----- Machi wrote: ----

Can anyone provide any advice or article on creating DataGrid and bind it with data but for every column of data, there may be different Server Controls. To make it clear, let say i want bind 1 field in one DataGrid, but for the only field i want to bind, i may have Label control from rows 1 - 5 and , i want to bind checkboxes to rows from row 6 - 8 and i want to bind again the label controls from row 9 - 11. Can i do that in DAtagrid in ASP.NET ???? Thanks you very much
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.