如何在GridView中获取此ItemTemplate字段的值? [英] How to get the value of this ItemTemplate field in the GridView?

查看:63
本文介绍了如何在GridView中获取此ItemTemplate字段的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个简单的事件管理系统,并且有一个GridView可以显示事件的信息,包括标题,描述,位置等.我将标题字段设置为LinkBut​​ton,因为我希望用户单击它以显示一个新的PopUp窗口以注册该事件.现在.我想获得标题值,以将其包含在单击注册"按钮后将发送给用户的电子邮件中.

如何获取标题"字段的值而不是获取空文本?


仅供参考,对于弹出窗口,我正在使用Ajax ModalPopUpExtender.


ASP.NET代码:

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>



代码隐藏(C#):



Code-Behind (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();
    }

推荐答案

尝试一下
LinkButton lnbTitle =(LinkButton) gvrow.FindControl("lnkTitle");
lblTitle.Text = lnbTitle.Text ;


GridViewRow row=(GridViewRow)gridview1.row[e.rowindex];
LinkButton lb=(LinkButton)row.FindControl("linkbuttonname");
string str=lb.text;


试试这个....


try this....


这篇关于如何在GridView中获取此ItemTemplate字段的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆