Populate Gridview from Javascript

Posted on 2009-04-15
Medium Priority
Last Modified: 2013-11-26
Does anyone know if you can populate a Gridview from Javascript. Perhaps return an XML dataset from a PageMethods and somehow update the Grid?
Question by:Jeffreymarcum
1 Comment

Accepted Solution

parul11183 earned 2000 total points
ID: 24148760
CHECK this out:---
The JS:

function fillAll(frstTxtBox)
        // get the value of the first date input field
        var frstBoxVal = document.getElementById(frstTxtBox).value;
        // get all of the input elements
        var inputElements = document.getElementsByTagName("input");
        for (i = 0; i < inputElements.length; i++)
            // if it's a text box and has an 'index' attribute witht a value greater than zero...
            if (inputElements[i].type == "text" && inputElements[i].index > 0)
                inputElements[i].value = frstBoxVal;

<asp:TextBox ID="txtRequestDate" Text='' Width="75" runat="server"></asp:TextBox>
<asp:HyperLink ID="hlFill" NavigateUrl='<%# "javascript:fillAll(&#39;" +((GridViewRow)Container).FindControl("txtRequestDate").ClientID + "&#39;)"%>'

protected void gvCheckout_RowCreated(Object sender, GridViewRowEventArgs e)

            if (e.Row.RowType == DataControlRowType.DataRow)
                for (int i = 1; i < e.Row.Cells.Count - 1; i++)
                    ((TextBox)e.Row.FindControl("txtRequestDate")).Attributes.Add("index", e.Row.RowIndex.ToString());
                    if (e.Row.RowIndex == 0)
                        e.Row.FindControl("hlFill").Visible = true;

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question