.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Accessing a datagrid element using javascript

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :ASP.Net
Hi all,as I'm not a .Net developer, I'm struggling with some simple problems using the language. I'm trying to insert some javascript functionality, inside my page. What I'm trying to do below...<script language=javascript> function ControlBackupFields(hasBackup) { if (hasBackup.checked = true) { document.aspnetForm.frequencyValue.enabled = true; document.aspnetForm.frequencyUnitList.enabled = true; } else { document.aspnetForm.frequencyValue.enabled = false; document.aspnetForm.frequencyUnitList.enabled = false; } } </script> <asp:datagrid id="dgData" runat="server" AutoGenerateColumns="False" PageSize="20" Width="100%" CssClass="grid" CellPadding="1"> <ItemStyle Height="20px" CssClass="tabletext2" VerticalAlign="Top"></ItemStyle> <HeaderStyle Height="20px" CssClass="tableheading2"></HeaderStyle> <Columns> <asp:TemplateColumn> <ItemTemplate> <asp:TextBox id="volumeID" Runat="server" Visible="false" /> <asp:Label id="volumeName" Runat="server" /> </ItemTemplate> </asp:TemplateColumn> <asp:Templa

View Complete Post

More Related Resource Links

Accessing Label Control In a listview using Javascript



I have a Button and Label nested inside a ListView.

When a User clicks the button i want the Label to display a specific value eg"Pass". Of course being a Listview the Label value will be relevant to the row the button was clicked on.

I want all this to happen on client side, but i am struggling to access the Label via my Javascript??

Any suggestions and examples Would be much appreciated..

Accessing Combobox inside WPF Datagrid Template Column

Hi, I am creating a WPF datagrid template column with combobox. The problem that I face now is, I am not able to bind a table to the combobox inside the WPF datagrid template column. Here is the code snippet. <dg:DataGrid x:Name="Students" AutoGenerateColumns="False" Loaded="OnLoad"> <dg:DataGrid.Columns> <dg:DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" Width="75"/> <dg:DataGridTemplateColumn x:Name="Dept"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox x:Name="DeptId" ItemsSource="{Binding}" SelectionChanged="Dept_SelectionChanged" DisplayMemberPath="{Binding Path=DeptName}" SelectedValuePath="{Binding Path=DeptId}" SelectedItem="{Binding Path=Belongs}"/> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> </dg:DataGrid.Columns> </dg:DataGrid> Please help me to find out the way to assign a dynamic source to the combobox through code behind file. Thanks in Advance!!! Best Regards, Subalakshmi Vijayarajan.

How to execute javascript function from datagrid row

 Hi I need to execute  a javascript function when a row of a datagrid is clicked. I am not sure how to do this. I have tried adding a template column with a button <asp:TemplateColumn>  <ItemTemplate>    <asp:Button ID="myButton" Text="Insert collection" OnClientClick="putData();" runat="server" />  </ItemTemplate></asp:TemplateColumn> And then attaching the javascript to it: myButton.Attributes.Add("onclick", "putData()") But it produces an error. Sorry this is a basic question, but what am I doing wrong?

Passing invisible element to javascript function


I want to pass the name of a listbox to a javascript function which will make it visible. The listbox element must start out invisible. But when the server generates the source, it does not create the element because it is invisible. So the javascript functions doesn't get anything. How to do this?

    function promote(boxid) {
        document.getElementById(boxid).style.visibility = "visible";
        document.getElementById(boxid).style.zIndex = 100;


    <asp:ListBox ID="ListBox1" runat="server" CssClass="PosAbs0" Visible="False"
        SelectionMode="Multiple" ToolTip="Ctrl-Click to select multiple items">
        <asp:ListItem Selected="True">All Breed</asp:ListItem>

check or uncheck boxes in datagrid using Javascript


Here is the situation: I have a checkbox in the header of the datagrid and I want to use Javascipt so when I check the box, all of the checkboxes in the datagrid are checked (or unchecked if the one on top is unchecked).  How do I reference the asp:checkboxes in the datagrid?

<script type="text/javascript" language="javascript" id="clientEventHandlersJS">
    function SelectAll(isChecked) {
        var chkb = document.getElementsByTagName('asp:checkbox')
        for (var i = 1; i < chkb.length; i++) {
            chkb[i].checked = isChecked;

<asp:DataGrid id="DataGrid2" runat="server">
        <asp:TemplateColumn SortExpression="InMailing" HeaderText="In Mailing">
            <HeaderTemplate >

Accessing External Javascript files (.js) in VWD 2010 (.Net 4)


Hopefully I've selected the appropriate forum to post. If not, kindly let me know and I will post in that forum.

I have searched hundreds of posts over countless forums, but am unable to run a Javascript that is placed in a separate .js file. If the script is placed directly in the <HTML> and ASP markup, the script runs fine. I am a newbie at this and resolution may be quite simple. But I cannot figure it out.

I have simplied the example down to a single .aspx page with a single button and the codebehind in VB, knowing that if I cannot get this working, I certainly won't be able to get my real scripts working.

I am currently running VWD 2010 on the .Net 4 framework. I've been working on this problem on and off over the past 3 weeks and simply cannot get it to work, so I continue to insert the code directly into the markup. I have tried countless changes to the following code, but not once able to get it to work.

Any help, suggestions or recommendations will be graciously accepted and very much appreciated.


The .aspx page is as follows:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test_Script.aspx.vb" Inherits="Test_Script" %>



Run javascript before sorting or paging the datagrid


Here is what I am trying to do;

I want it so that when the user clicks on the datagrid column headers to sort the records, or when they go to page the datagrid, that a confirmation pop-up appears first, confirming that their changes are going to be lost (unless they click "Cancel").

I have the confirmation pop-up scripted in Javascript and is added to the controls on the page using

onClientClick="return ConfirmDiscardChanges();"

How do I attach this to a datagrid header and to the pager?

Do the columns need to be Template columns and the header text being hyperlink?  If so, how do I set it up so it will, if the user clicks "OK" in the confirmation pop-up,  still sort?


Edit a DataGrid row's style by Javascript when a control is clicked.


I have a datagrid I am working with which has a few columns, but one checkbox with a javascript onclientclip event.

I want to highlight the row that the checkbox is clicked, highlighting for the user that this record has changed.

I have a CSS Class of "GrdHiglight" that can be used to override the "GrdNorm" and "GrdAlt" classes, or if I have to manually change the style for the row that is fine.

How do I reference the one row which the checkbox resides in, in the datagrid, to modify this?

Nested DataGrid - Accessing parent selected row from child in MVVM

Hi All,

I have a nested datagrid. The child datagrid is inside the RowDetailsTemplate.
I have expander and collapse button to open the child datagrid. When i select the expander/collapse button, the row of the parent datgrid gets selected and the child datagrid is loaded with data. Next, i select the child datagrid row. So the problem is when i am selecting the child datagridrow, the parent datagrid row selection should be deselected.

This needs to be achieved in MVVM

Please help.

Accessing GridView TemplateField using Javascript



I have a GridView in which i have some Template Fields including a button as template field also here is the link which i have implemented so u will know what i am talking about. problem is that on clicking of UpdateButton I am calling a javascript to save values of template field boxes of particular row but I cannot access the template field textboxes from javascript. how to do that.


now my problem is that i have update button in that nested template area which is calling a javascript to update the particular grid row nested data using AJAX.

here is my version the way I am doing.

   <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" DataKeyNames="Bill_Generation_ID"
            OnRowDataBound="GridView1_RowDataBound" CellPadding="3"
        GridLines="None" EnableModelValidation="True" BackColor="White" 
            BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellSpacing="1" 
              CssClass="mGrid" Font-Names="Verdana" Font-Size="12px">

Adding meta element under head tag through javascript


I have created an aspx page in sharepoint desinger with one webpart zone containing content editor webpart. 

now i want to add the meta elements like <meta name="keywords" content="a,b,c"/> through javascript. 

I have written below mentioned javascript in content editor webpart but its not coming in head section. 

<script type="text/javascript"> var meta =document.createElement('meta');

// set properties

meta.name = "keywords"; meta.content = "A,b,c";

// now add the meta element to the head



Anyone has any idea does my approach is right or wrong?

Thanks -NK

JavaScript, passing reference to a form element question


I have a simple audio player that is controlled with JavaScript initiated by ASP.NET imagebuttons. When the user clicks on the "play" button the image is switched out for a different button image to make it "light up" while playing; when the player is finished the original image is put back so the button appears dark again. Originally, I was doing this by hardcoding in the client element ids for the image buttons ("ctl00_Middle_Voice1_LoginView1_StartLoad"), but that restricted where I could use the control. So, I have switched it so that in the ImageButton OnClientClick function I pass in 'this' and then refer to that control in the function to change the image source.

This works fine for the initial function called by OnClientClick (Play), but that function in turn calls a second function to determine the timing, control the progress bar, and whether or not the player is done playing yet and if so to swap back the original image. In that second function (Timing), I get a null object reference if I try to pass the element in again as an argument.

I have tried getting the id of the element and passing that instead (and then locating the element from the second function with getElementByID), but get the same error.

<eo:ProgressBar ID="ProgressBar1" runat="server" BorderColor="Black" BorderWidth="1px" IndicatorColor="Red" Hei

Problem in Accessing Server Controls Value or ID in JavaScript



I have a master page MasterPage.master


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <asp:ContentPlaceHolder id="head" runat="server">
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">



And a Content Page Default.aspx


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
  <script language="javascript" type="text/javascript" src="JScript.js"></script>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHol

ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

call JavaScript - jQuery code from ASP.NET Server-Side

jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend