Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid: Expanding Row Display

Status
Not open for further replies.

ISPrincess

Programmer
Feb 22, 2002
318
US
I have a datagrid that will display about 5 columns with One row each in an ItemTemplate.

Here is a sample of the first column:

Code:
<ItemTemplate>
<% databinder.eval(container.dataitem "InfoField") %>
</ItemTemplate>

I have a + sign that when clicked, I would like to expand that row to show more information. Such as:

Code:
<ItemTemplate>
<% databinder.eval(container.dataitem "InfoField") %>
<BR>
<% databinder.eval(container.dataitem "MoreInfo") %>
</ItemTemplate>

This is not a parent/child thing. I just need to save real estate until a user needs to see alittle more data by row.

I saw an example of this while searching the web, but cannot find it again.

Later, I will need to nest a child grid inside this parent grid also, but that is a seperate issue, Which I am also having a very difficult time with.

Any help, especially on the first issue (show more information) would be greaty appreciated!



PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
I've done something similar to this but I can't find it. The way I did it was similar to the following. The following code changes the background and forecolor if the row is selected or not. I had to create a hidden field to store the selected value due to postbacks.

public void dgModules_ItemDataBound(Object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Header & e.Item.ItemType != ListItemType.Footer)
{
LinkButton lnkModules = (LinkButton)e.Item.Cells[0].Controls[1];

string strItem = Convert.ToString(dgModules.DataKeys[e.Item.ItemIndex]);

if (strItem == lblSelectedModule.Text)
{
lnkModules.ForeColor = colorTextBack;
lnkModules.BackColor = colorMain;
}
else
{
lnkModules.ForeColor = colorMain;
}
}
}

public void dgModules_ItemCommand(Object source , System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgModules.SelectedIndex = Convert.ToInt32(e.Item.ItemIndex);
lblSelectedModule.Text = Convert.ToString(dgModules.DataKeys[e.Item.ItemIndex]);
}

Hope this points you in the right direction.

I just posted something on your second issue today.


Hope everyone is having a great day!

Thanks - Jennifer
 
Maybe I misunderstand your post (I am not experienced in C), but I am not trying to change the color, I am trying to expand on the data contained in the item template by adding more fields with databinder.eval(...

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Replace the color section with your controls and the visible property. When it isn't selected, the other fields would not be visible. When it is selected to show the other fields, they would be.

The theory should be the same.

I am just learning C# so I understand language.

if strItem = lblSelectedModule.Text then

lblOne.Visible = true
lblTwo.Visible = true

else
lblOne.Visible = false
lblTwo.Visible = false
end if

Hope this helps.


Hope everyone is having a great day!

Thanks - Jennifer
 
Oh, thanks.

I wonder if it would be too much bother to ask you to post alittle of the HTML from the grid to show that lbl?


PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
It wouldn't necessarily be in the HTML. You have to create a variable and set it in the code to be able to refer to it.

Dim lblOne As Label = e.Item.Cells(0).Controls(1)
Dim lblOne As Label = e.Item.Cells(0).Controls(2)

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top