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
Solved

populate gridview id in alert box

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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