Solved

Populate Gridview from Javascript

Posted on 2009-04-15
2
875 Views
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?
0
Comment
Question by:Jeffreymarcum
2 Comments
 
LVL 1

Accepted Solution

by:
parul11183 earned 500 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;
            }
        }
    }

THE ASP.NET
<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;)"%>'

THE C# CODE
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;
                    }
                }
               
            }
           
        }
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now