Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDown and Datagrid

Status
Not open for further replies.

wudang26

Technical User
May 18, 2012
7
US
I'm trying to get my function to display a value or make a label visible once you select a certain value from the dropdown thats in my datagrid. Is there a way to do this

Any help would be appreciated.


<script language="javascript" type="text/javascript">

function OnChange()
{

var IndexValue = document.getElementById('<%=myDataGrid.ClientID %>').getElementsByTagName(".selectedIndex;

var SelectedVal = document.getElementById('<%=myDataGrid.ClientID %>').options[IndexValue].text;

alert(SelectedVal);

}
//-->
</SCRIPT>


<asp DataGrid ID="myDataGrid" runat="server" AutoGenerateColumns="False"
BackColor="AntiqueWhite" BorderColor="Black" CellPadding="3"
Font-Name="Verdana" Font-Names="Verdana"
Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
Width="909px" DataSourceID="SqlDataSource1"
onselectedindexchanged="myDataGrid_SelectedIndexChanged">
<HeaderStyle BackColor="Maroon" ForeColor="White" />

<Columns>
<asp:TemplateColumn HeaderText="Select Action">
<ItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" onchange="javascript:OnChange(this);" Enabled="True">
<asp:ListItem Value ="0" >Select an Action</asp:ListItem>
<asp:ListItem Value ="1" >Drop</asp:ListItem>
<asp:ListItem Value ="2" >Change</asp:ListItem>
</aspropDownList>
</ItemTemplate></asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Term">
<ItemTemplate>
<asp:Label ID="Term" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "STRM") %>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp DataGrid>
 

Have you tried adding the call in your ItemDataBound event rather than the ItemTemplate?

Code:
 Dim ddl As DropDownList
        If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
            ddl = CType(e.Item.FindControl("DropDownList1"), DropDownList)
            ddl.Attributes.Add("OnChange", "OnChange(this)")
        End If


Code:
function OnChange(ddl) {
    var selection = ddl.options[ddl.selectedIndex].value; 
    alert(selection);
}


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
[ol]
[li] Posting server side code is of no use to debugging JavaScript. Always post the rendered HTML from the view source option of your browser, as that is what JavaScript actually interacts with.[/li]
[li]server side code like ASP runs on the server, by the time JavaScript does its thing, your variables will have been replaced by their values in ASP, and be static, so best case scenario, you are going to show the same element every time [/li]
[li] You are missing a parenthesis, so tour code is likely to be producing an error, and halting execution at that point.[/li]
[/ol]

Code:
var IndexValue = document.getElementById('<%=myDataGrid.ClientID %>').getElementsByTagName[red][b]([/b][/red]".selectedIndex[red]>><<[/red];


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown. 

[url=http://behindtheweb.blogspot.com/] Web & Tech [/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top