Droplist in Header of DataGrid. Possible?

  • Thread starter hoosierprogrammer
  • Start date
H

hoosierprogrammer

Is it possible to locate a droplist inside the header of a column next
to the headertext?

The droplist is created independent of the datagrid and is not related
to the data in the grid itself.

Has anyone done this?

TD
 
A

Alvin Bruney [MVP]

just add the control to the header item in the itemdatabound event
e.item.cells[23].controls.add(droppdownlist1);
roughly
 
H

hoosierprogrammer

Thanks Alvin,

That got me pointed in the right direction. A little trouble though.

With this code (below), the single column datagrid disappears except
for the header and it does not have the dropdown in it. I'm pretty
sure that it is firing because when I comment it out, the grid
reappears.

Thoughts?

Thanks for your help.

TD



protected void DGridAllGroupList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);

}





















Alvin Bruney said:
just add the control to the header item in the itemdatabound event
e.item.cells[23].controls.add(droppdownlist1);
roughly

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Is it possible to locate a droplist inside the header of a column next
to the headertext?

The droplist is created independent of the datagrid and is not related
to the data in the grid itself.

Has anyone done this?

TD
 
A

Alvin Bruney [MVP]

you need to only put the control in the header not the other cells
change your code to

if(e.Item.ItemType == ListItemType.Header)

{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);
}


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thanks Alvin,

That got me pointed in the right direction. A little trouble though.

With this code (below), the single column datagrid disappears except
for the header and it does not have the dropdown in it. I'm pretty
sure that it is firing because when I comment it out, the grid
reappears.

Thoughts?

Thanks for your help.

TD



protected void DGridAllGroupList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);

}





















Alvin Bruney said:
just add the control to the header item in the itemdatabound event
e.item.cells[23].controls.add(droppdownlist1);
roughly

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Is it possible to locate a droplist inside the header of a column next
to the headertext?

The droplist is created independent of the datagrid and is not related
to the data in the grid itself.

Has anyone done this?

TD
 
H

hoosierprogrammer

PERFECT !

I'm not quite sure why the cell index needs to be 1 (I was thinking
0), but that's anohter issue.

Thanks for your help. Here's the final code.

TD


protected void DGridAllGroupList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
e.Item.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Item.Cells[1].Controls.Add(ddGroup);
}
}









Alvin Bruney said:
you need to only put the control in the header not the other cells
change your code to

if(e.Item.ItemType == ListItemType.Header)

{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);
}


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thanks Alvin,

That got me pointed in the right direction. A little trouble though.

With this code (below), the single column datagrid disappears except
for the header and it does not have the dropdown in it. I'm pretty
sure that it is firing because when I comment it out, the grid
reappears.

Thoughts?

Thanks for your help.

TD



protected void DGridAllGroupList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);

}





















Alvin Bruney said:
just add the control to the header item in the itemdatabound event
e.item.cells[23].controls.add(droppdownlist1);
roughly

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Is it possible to locate a droplist inside the header of a column next
to the headertext?

The droplist is created independent of the datagrid and is not related
to the data in the grid itself.

Has anyone done this?

TD
 
A

Alvin Bruney [MVP]

if you have a select button in index 0 then you need to start counting at 1

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
PERFECT !

I'm not quite sure why the cell index needs to be 1 (I was thinking
0), but that's anohter issue.

Thanks for your help. Here's the final code.

TD


protected void DGridAllGroupList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
e.Item.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Item.Cells[1].Controls.Add(ddGroup);
}
}









Alvin Bruney said:
you need to only put the control in the header not the other cells
change your code to

if(e.Item.ItemType == ListItemType.Header)

{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);
}


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thanks Alvin,

That got me pointed in the right direction. A little trouble though.

With this code (below), the single column datagrid disappears except
for the header and it does not have the dropdown in it. I'm pretty
sure that it is firing because when I comment it out, the grid
reappears.

Thoughts?

Thanks for your help.

TD



protected void DGridAllGroupList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Cells[0].Text = "Test";
e.Item.Cells[0].Controls.Add(ddGroup);

}





















"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
just add the control to the header item in the itemdatabound event
e.item.cells[23].controls.add(droppdownlist1);
roughly

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Is it possible to locate a droplist inside the header of a column
next
to the headertext?

The droplist is created independent of the datagrid and is not
related
to the data in the grid itself.

Has anyone done this?

TD
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top