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 said:
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_type_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.