DataGrid having ListBox and Hyperlink

G

Guest

I have a datagrid, it has dropdown box as a column and i have one more column
that has hyperlink. The NavigateURL for the hyperlink is to open a new window
with a query stirng parameter as the selected value of the drop down...

here is how it looks like

<asp:datagrid....>
....
<asp:TemplateColumn>
<ItemTemplate>
<asp:ListBox
ID="ItemList" Runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDown_SelectedIndexChanged"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:hyperlink runat='server' id='PocketDetails'/asp:hyperlink>
</ItemTemplate>
</asp:TemplateColumn>

....
</asp:datagrid>

The url for the hyperlink contorl ("PocketDetails") has to be created
dynamically and with the querysting parameter as the selected value of
dropdown box ("ItemList").

How do I achieve this?

Thanks for your help
 
O

Ollie Riches

so you when a user selects a entry in the drop down list you want to change
the hyperlink on the post back event?

If so what you want to do is add a handler for the drop down list and do
something like this get the current datagrid item index.

private void ddlXXX_SelectedIndexChanged(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.DataGridItem item = null;
item = ((System.Web.UI.WebControls.DropDownList)sender).Parent.Parent;

int currentIndex = item.ItemIndex;
string newUrl = "<MAKE URL>";

System.Web.UI.WebControls.HyperLink link = null;
System.Web.UI.WebControls.HyperLink =
(System.Web.UI.WebControls.HyperLink)item.FindControl("PocketDetails'");

link.NavigateUrl = newUrl;
}


--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.
 
G

Guest

Ollie,
Thank you so much.. This what exactly I wanted. May I ask you, why we are
doing 2 times Parent.Parent as in the statement

item = ((System.Web.UI.WebControls.DropDownList)sender).Parent.Parent;
 
O

Ollie Riches

I believe the parent of the dropdown list is the cell and the parent of that
is the DataGridItem

--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.
 

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

Top