Solved

populate gridview id in alert box

Posted on 2007-04-02
3
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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