Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...What you have done for people like me is immeasurably helpful."

Geography

Where in the world do Tek-Tips members come from?
wudang26 (TechnicalUser)
26 Jul 12 8:45
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>
MarkSweetland (MIS)
26 Jul 12 9:30

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

vacunita (Programmer)
26 Jul 12 10:21
  1. 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.
  2. 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
  3. You are missing a parenthesis, so tour code is likely to be producing an error, and halting execution at that point.
[code]
var IndexValue = document.getElementById('<%=myDataGrid.ClientID %>').getElementsByTagName(".selectedIndex>><<;

----------------------------------
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.

Web &amp; Tech

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close