Different Server Controls in DataGrid

G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top