Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

I am developing a simple events management system and I have a GridView that shows the information of the event including title, description, location... etc. I made the title field as a LinkButton because I want the user to click on it to show a new PopUp window to register in the event. Now. I want to get the title value to include it in the email that will be sent to the user after clicking on the Register button.

How to get the value of Title field instead of getting empty text?


FYI, for the PopUp Window, I am using Ajax ModalPopUpExtender.


ASP.NET code:
<asp:GridView ID="ListOfAvailableEvents_GrivView" runat="server" AutoGenerateColumns="False"
                    DataKeyNames="ID" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
                    GridLines="None" AllowPaging="True" PageSize="10">
                    <Columns>
                        <asp:TemplateField HeaderText="Title">
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkTitle" runat="server" Text='<%# Eval("Title") %>' OnClick="lnkTitle_Click"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
                        <asp:BoundField DataField="StartDateTime" HeaderText="Start Date & Time" SortExpression="StartDateTime" />
                        <asp:BoundField DataField="EndDateTime" HeaderText="End Date & Time" SortExpression="EndDateTime" />
                    </Columns>
                </asp:GridView>


Code-Behind (C#):
C#
protected void lnkTitle_Click(object sender, EventArgs e)
    {
        //to get the GridViewRow from the sender, so we can get the datakey we need
        //GridViewRow gvrow = (GridViewRow)((LinkButton)sender).Parent.NamingContainer;
        GridViewRow gvrow = (GridViewRow)(((LinkButton)sender)).NamingContainer;
        HiddenField1.Value = ListOfAvailableEvents_GrivView.DataKeys[gvrow.RowIndex].Value.ToString();

        lblTitle.Text = gvrow.Cells[0].Text;
        lblDescription.Text = gvrow.Cells[1].Text;
        lblLocation.Text = gvrow.Cells[2].Text;
        lblStartDateTime.Text = gvrow.Cells[3].Text;
        lblEndDateTime.Text = gvrow.Cells[4].Text;

        //show the modalPopUp
        modalPopupExtender1.Show();
    }
Posted
Comments
Vani Kulkarni 14-Aug-12 5:54am    
Can you post your register button click code?

Try this
C#
LinkButton lnbTitle =(LinkButton) gvrow.FindControl("lnkTitle");
lblTitle.Text = lnbTitle.Text ;
 
Share this answer
 
C#
GridViewRow row=(GridViewRow)gridview1.row[e.rowindex];
LinkButton lb=(LinkButton)row.FindControl("linkbuttonname");
string str=lb.text;

try this....
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900