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.