0

I'm trying to code a Gridview that has a button on each row that when clicked will expose that particular rows data for use, but I'm not sure how the data would be passed.

The Gridview:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
    DataSourceID="SqlDataSource2">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
            SortExpression="ID" Visible="False" />
        <asp:BoundField DataField="RelationID" HeaderText="RelationID" InsertVisible="False"
            SortExpression="RelationID" Visible="False" />
        <asp:BoundField DataField="UserRole" HeaderText="UserRole" InsertVisible="False"
            SortExpression="UserRole" Visible="False" />
        <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
        <asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
        <asp:BoundField DataField="Telephone" HeaderText="Telephone" SortExpression="Telephone" />
        <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
        <asp:BoundField DataField="Hash" HeaderText="Hash" InsertVisible="False" SortExpression="Hash"
            Visible="False" />
        <asp:BoundField DataField="DateCreated" HeaderText="Date Invited" SortExpression="DateCreated" />
        <asp:TemplateField HeaderText="Resend Welcome Email">
            <ItemTemplate>
            <asp:Button runat="server" ID="btnResend" Text="Resend" OnClick="btnResend_Click" />
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        </asp:TemplateField>
    </Columns>
</asp:GridView>

The button_OnClick

protected void btnResend_Click(object sender, EventArgs e)
{
    bool boolEmailSent = Email.sendWelcomeEmail(//Email from Row, //FirstName from Row, //Surname from Row, //Hash from Row);

    if (boolEmailSent == true)
    {
        //Confirm to User
    }
    else
    {
        //TODO: write error to log
    }
}

1 Answer 1

1

This article covers what you're attempting in more depth than we could answer here:

http://authors.aspalliance.com/aspxtreme/webforms/controls/addingbuttonfieldstoGridView.aspx

And here's another:

http://msdn.microsoft.com/en-us/library/bb907626.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for those. Did the job perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.