473,834 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById("ISMS_ List__ctl1_mni_ inv_type_ddl");
var the_index = the_select.sele ctedIndex;
o.mni_type_code = the_select.opti ons[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 3918
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.ItemT ype == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem || e.Item.ItemType ==
ListItemType.Se lectedItem)

{

DropDownList dl=(DropDownLis t)e.Item.FindCo ntrol("dlist1") ;

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

Button b1=(Button)e.It em.FindControl( "button1");

build your cleint side script here :

AS you need client side event onclick to each button,

b1.Attributes.A dd("onclick","a lert('" + dl.SelectedInde x + "');");

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.goo gle.com...
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.getEle mentById("ISMS_ List__ctl1_mni_ inv_type_ddl"); var the_index = the_select.sele ctedIndex;
o.mni_type_code = the_select.opti ons[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 GetSelectedInde x(index){
var selected_dl=doc ument.getElemen tById(index);
var selected_index= selected_dl.sel ectedIndex; alert("Index : " +
selected_index + " Value : " + selected_dl.opt ions[selected_index].text);
}
server side code is :
private void DataGrid1_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)

{
if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType ==

ListItemType.Al ternatingItem || e.Item.ItemType ==

ListItemType.Se lectedItem)

{

i=i+1;
DropDownList dl=(DropDownLis t)e.Item.FindCo ntrol("dlist1") ;

dl.SelectedInde x=j;

Button b1=(Button)e.It em.FindControl( "button1");

b1.Text= " Button " + i;

b1.Attributes.A dd("onclick","G etSelectedIndex ('" + 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******** ******@tk2msftn gp13.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.ItemT ype == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem || e.Item.ItemType ==
ListItemType.Se lectedItem)

{

DropDownList dl=(DropDownLis t)e.Item.FindCo ntrol("dlist1") ;

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

Button b1=(Button)e.It em.FindControl( "button1");

build your cleint side script here :

AS you need client side event onclick to each button,

b1.Attributes.A dd("onclick","a lert('" + dl.SelectedInde x + "');");

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.goo gle.com...
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.getEle mentById("ISMS_ List__ctl1_mni_ inv_type_ddl");
var the_index = the_select.sele ctedIndex;
o.mni_type_code = the_select.opti ons[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
2522
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 simple, but in VB .NET there is a property ClientID and I get an error, a conflict beetwen my clientID and ClientID of MyBase class aspx code: ****
2
1922
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 "_MyControl1__ctl16". But then, on the final HTML rendered, if you look at the page, the textbox looks like this:
25
4080
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
1516
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 Client ID of a form field from within a DataGrid like this: <%= FormFieldID.ClientID %>. At least, not without extra work. How did I do this? I created a new DataGrid from scratch, with a form above it and a form inside of it. This was a page...
2
1975
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 displaying pages and pages of rows. When I edit some row below pages 1 the post refreshes back to page one, requiring me to page down to do the input.
2
1780
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 buttons. I am doing dynamic HTML which I only know how many buttons and context menu to create on the fly. Next I had written a simple JAvascript which will allow the dialogs (i.e. the context menu's tables) to be placed at the correct location when
4
7780
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 ChangePanel() { document.getElementById("<%=Panel1.ClientID %>").style.display =
2
6759
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(); addedControl.ID = "addedControl"; pagerCell.Controls.Add(addedControl);
0
1045
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 get the clientid of each dropdown list. One way i know is to get the client id by view source, but that does not solve the problem.Is there any way that i can get the client id of each dropdown using some simple javascript because i want to add...
0
9643
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10790
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7755
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6952
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.