Solved

populate gridview id in alert box

Posted on 2007-04-02
3
239 Views
Last Modified: 2008-02-01
How do I populate gridview id in alert box?

aspx

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CCPaymentId" Font-Size="XX-Small" Width="776px" CellPadding="0" OnRowDataBound="GridView1_RowDataBound">
            <Columns>
                <asp:BoundField DataField="ccPaymentid" HeaderText="ID" ReadOnly="True" SortExpression="ccPaymentid"/>

-------------
aspx.cs

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string alertBox = "alert('";
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            alertBox += "You selected Index: ";
            alertBox += e.Row.RowIndex + " and the Id: ";
            alertBox += e.Row.FindControl("ccPaymentid"); //not finding it
            alertBox += "')";
            e.Row.Attributes.Add("onclick", alertBox);
        }
    }
0
Comment
Question by:fwsteal
  • 3
3 Comments
 
LVL 3

Expert Comment

by:emailrobertwalker
ID: 18838760
Here is how I access my gridview properties in the RowDataBound

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound, GridView2.RowDataBound
        '
        If e.Row.RowType = DataControlRowType.DataRow Then
            If (e.Row.DataItem("FileType") = 0) Then
                e.Row.Cells(2).Text = "Song"
            ElseIf (e.Row.DataItem("FileType") = 1) Then
                e.Row.Cells(2).Text = "Sheet Music"
            ElseIf (e.Row.DataItem("FileType") = 2) Then
                e.Row.Cells(2).Text = "Movie"
            ElseIf (e.Row.DataItem("FileType") = 3) Then
                e.Row.Cells(2).Text = "Other"
            End If
        End If
        '
    End Sub
0
 
LVL 3

Accepted Solution

by:
emailrobertwalker earned 500 total points
ID: 18838773
So would you change the line

e.Row.FindControl("ccPaymentid");
to
e.Row.DataItem("ccPaymentid")
?
0
 
LVL 3

Expert Comment

by:emailrobertwalker
ID: 18838794
Wow that was fast! Glad I could help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 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

8 Experts available now in Live!

Get 1:1 Help Now