Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

populate gridview id in alert box

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
fwsteal
Asked:
fwsteal
  • 3
1 Solution
 
emailrobertwalkerCommented:
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
 
emailrobertwalkerCommented:
So would you change the line

e.Row.FindControl("ccPaymentid");
to
e.Row.DataItem("ccPaymentid")
?
0
 
emailrobertwalkerCommented:
Wow that was fast! Glad I could help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now