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.
 
Joined
Jan 27, 2010
Messages
27
Reaction score
0
Change the UI of ListBox and DropDownList on the fly

1. From ServerSide (In c#)

To change ListBox to DropDownList just change the Rows property of the ListBox with “1” Then it will behave as the Dropdown list in UI.
→ ListBox1.Rows = 1;

For the reverse Add
→ DropDownList1.Attributes.Add("size", "3");

2. In ClientSide (By Javascript)
DropDownList & Listbox Both rendered as select in the browser differentiate in their size property. So to change the UI of DropDownList to ListBox just change this property


<input id="Button1" type="button" value="button" onclick="ToggleView();"/>


<script type="text/javascript">
function ToggleView()
{
document.getElementById('ListBox1').size = 1; // This will Change from listBox to Dropdown List.
document.getElementById('DropDownList1').size = 3;// This will Change from Dropdown List to listBox.
}
</ script>


A small may be useful idea can be: Save the page space by showing the options in a DropDownList & on mousover change it to listbox & again on mouseout do the reverse.
Here is the sample code


<asp:ListBox ID="ListBox1" runat="server" Rows="3" onmouseover="javascript:document.getElementById('ListBox1').size = 3;"
onmouseout ="javascript:document.getElementById('ListBox1').size = 1">
< asp:ListItem>Option 1</asp:ListItem>
< asp:ListItem>Option 2</asp:ListItem>
< asp:ListItem>Option 3</asp:ListItem>
</ asp:ListBox>
 
Joined
Jan 27, 2010
Messages
27
Reaction score
0
Change the UI of ListBox and DropDownList on the fly

. From ServerSide (In c#)

To change ListBox to DropDownList just change the Rows property of the ListBox with “1” Then it will behave as the Dropdown list in UI.
→ ListBox1.Rows = 1;

For the reverse Add
→ DropDownList1.Attributes.Add("size", "3");

2. In ClientSide (By Javascript)
DropDownList & Listbox Both rendered as select in the browser differentiate in their size property. So to change the UI of DropDownList to ListBox just change this property


<input id="Button1" type="button" value="button" onclick="ToggleView();"/>


<script type="text/javascript">
function ToggleView()
{
document.getElementById('ListBox1').size = 1; // This will Change from listBox to Dropdown List.
document.getElementById('DropDownList1').size = 3;// This will Change from Dropdown List to listBox.
}
</ script>


A small may be useful idea can be: Save the page space by showing the options in a DropDownList & on mousover change it to listbox & again on mouseout do the reverse.
Here is the sample code


<asp:ListBox ID="ListBox1" runat="server" Rows="3" onmouseover="javascript:document.getElementById('ListBox1').size = 3;"
onmouseout ="javascript:document.getElementById('ListBox1').size = 1">
< asp:ListItem>Option 1</asp:ListItem>
< asp:ListItem>Option 2</asp:ListItem>
< asp:ListItem>Option 3</asp:ListItem>
</ asp:ListBox>
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top