Solved

populate gridview id in alert box

Posted on 2007-04-02
3
238 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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.

707 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

15 Experts available now in Live!

Get 1:1 Help Now