473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How do I use the ClientID with a dropdownlist?

jm
I have datagrid. On this datagrid there is a button and a
dropdownlist.

When I press the button, I want the selectedIndex of the dropdownlist.

There is a button and a dropdownlist for each datagrid row that is
populated from the database. Example, five rows returned, five
buttons, and five dropdownlists.

I know I am supposed to use the ClientID, but I cannot figure out how
to use ClientID to build the Javascript for each row returned. I just
can't picture it.

In regular Javascript, I can use:

var the_select = document.getElementById("ISMS_List__ctl1_mni_inv_t ype_ddl");
var the_index = the_select.selectedIndex;
o.mni_type_code = the_select.options[the_index].text;

But, of course, I need the correct name of the dropdownlist for the
row that I am on. I don't understand it. Please help. Thank you.
Nov 18 '05 #1
2 3896
Hi Jim,
Give an id for the drop down list in the aspx file.
If the id of the drop down is is dlist1,
In your ItemDataBound event of the grid,

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.SelectedItem)

{

DropDownList dl=(DropDownList)e.Item.FindControl("dlist1");

Put an id for the button as well.If the id of the buton is button1,

Button b1=(Button)e.Item.FindControl("button1");

build your cleint side script here :

AS you need client side event onclick to each button,

b1.Attributes.Add("onclick","alert('" + dl.SelectedIndex + "');");

This will add client side onclick to each button with their correspoding
SelectedIndex for the drop down..

I didn't test this code yet.So please make sure it works otherwise let me
know.

Hope this helps.

Regards,

Marshal Antony

..NET Developer

http://www.dotnetmarshal.com


"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have datagrid. On this datagrid there is a button and a
dropdownlist.

When I press the button, I want the selectedIndex of the dropdownlist.

There is a button and a dropdownlist for each datagrid row that is
populated from the database. Example, five rows returned, five
buttons, and five dropdownlists.

I know I am supposed to use the ClientID, but I cannot figure out how
to use ClientID to build the Javascript for each row returned. I just
can't picture it.

In regular Javascript, I can use:

var the_select = document.getElementById("ISMS_List__ctl1_mni_inv_t ype_ddl"); var the_index = the_select.selectedIndex;
o.mni_type_code = the_select.options[the_index].text;

But, of course, I need the correct name of the dropdownlist for the
row that I am on. I don't understand it. Please help. Thank you.

Nov 18 '05 #2
Hi Jim,
I thought I could create an example for you for your specific need.
You can put a javascript function on the aspx page client side and pass
the ClientID of the dropdownlist to it in the onclick of the button
from the server side.I have a button and dropdown list as template columns
in the datagrid and a datatable is created on the fly to populate
the datagid.I am attaching the aspx file and codebehind file from the
project as well.
Here is the code :
Javascript is :
function GetSelectedIndex(index){
var selected_dl=document.getElementById(index);
var selected_index=selected_dl.selectedIndex; alert("Index : " +
selected_index + " Value : " + selected_dl.options[selected_index].text);
}
server side code is :
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==

ListItemType.AlternatingItem || e.Item.ItemType ==

ListItemType.SelectedItem)

{

i=i+1;
DropDownList dl=(DropDownList)e.Item.FindControl("dlist1");

dl.SelectedIndex=j;

Button b1=(Button)e.Item.FindControl("button1");

b1.Text= " Button " + i;

b1.Attributes.Add("onclick","GetSelectedIndex('" + dl.ClientID + "');");

}

}

Hope this helps.

Regards,

Marshal Antony

..NET Developer

http://www.dotnetmarshal.com

of the
"Marshal Antony" <do***********@yahoo.com> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
Hi Jim,
Give an id for the drop down list in the aspx file.
If the id of the drop down is is dlist1,
In your ItemDataBound event of the grid,

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.SelectedItem)

{

DropDownList dl=(DropDownList)e.Item.FindControl("dlist1");

Put an id for the button as well.If the id of the buton is button1,

Button b1=(Button)e.Item.FindControl("button1");

build your cleint side script here :

AS you need client side event onclick to each button,

b1.Attributes.Add("onclick","alert('" + dl.SelectedIndex + "');");

This will add client side onclick to each button with their correspoding SelectedIndex for the drop down..

I didn't test this code yet.So please make sure it works otherwise let me know.

Hope this helps.

Regards,

Marshal Antony

.NET Developer

http://www.dotnetmarshal.com


"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have datagrid. On this datagrid there is a button and a
dropdownlist.

When I press the button, I want the selectedIndex of the dropdownlist.

There is a button and a dropdownlist for each datagrid row that is
populated from the database. Example, five rows returned, five
buttons, and five dropdownlists.

I know I am supposed to use the ClientID, but I cannot figure out how
to use ClientID to build the Javascript for each row returned. I just
can't picture it.

In regular Javascript, I can use:

var the_select =

document.getElementById("ISMS_List__ctl1_mni_inv_t ype_ddl");
var the_index = the_select.selectedIndex;
o.mni_type_code = the_select.options[the_index].text;

But, of course, I need the correct name of the dropdownlist for the
row that I am on. I don't understand it. Please help. Thank you.




Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maras | last post by:
Hello, as we know VB is not case sensivity. I have a following problem, I have to send to another server few parametrs by post or get method, one of them MUST be a "clientID", it's preety...
2
by: kw | last post by:
TextBox t=new TextBox(); Controls.Add(t); t.ID=t.ClientID; //reads: "_MyControl1__ctl16" And even in OnPreRender, I examine the Controls collection and verify that the ID of the TextBox is...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
by: Neo Geshel | last post by:
After pouring over about a dozen sites that clearly dealt with ClientID all by itself, I came to the realization that about 2/3+ of them were doing it wrong. It is indeed impossible to grab the...
2
by: jason | last post by:
Hello and Good Day. REALLY LOST. Running ASP.NET 1.1 Becuase I think I'm using my own controls smartnavigation does not appear to work for me. Stardard issue: I've got a datagrid thats...
2
by: JJ | last post by:
Hi, Can anyone advise me how is the ClientID issued? I had a suite Controls which consist of a context menu (i.e. a group of tables, rows and cells situated in a class library) and a set of...
4
by: Miguel Dias Moura | last post by:
Hello, I am having problems in accessing controls in my Asp.Net 2.0 pages. I know Asp.Net 2.0 generates a ClientId. In a Javascript function I tried to hide a panel as follows: function...
2
by: DC | last post by:
Hi, I am doing something like this in the ItemCreated event (ASP.Net 1.1): DataGridItem pagerRow = e.Item; TableCell pagerCell = pagerRow.Cells; Control addedControl = new Control();...
0
by: xpertbyshishir | last post by:
hi, i am creating a asp.net website in VB.net where i am generating dropdownlists for each row dynamically. When i am accessing this created controls in client side for handling, i am not able to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.