日期:2014-05-16  浏览次数:20485 次

GridView的RowCommand事件
在GridView的RowCommand事件里有LinkButton和HyperLink控件   现在要在点击LinkButton的时候获取对应行的HyperLink的属性

怎么实现。
------解决方案--------------------
(GridView1.Rows[0].Cells[0].Controls[0] as HyperLink).Text
 
------解决方案--------------------
很简单。

比如说你的模板是这样定义的

              <asp:TemplateField HeaderText="第一列">
                    <ItemTemplate>
                        <asp:HyperLink ID="MyHyperLink" runat="server" NavigateUrl='<%# GetDetailUrl((string)Eval("yf")) %>'
                            Text="链接" Visible='<%# Session["asdfas"]==null %>' Target="_blank"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:Panel runat="server" ID="PopupMenu">
                            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="胡乱点_Click" Text="胡乱点" </asp:LinkButton>
                        </asp:Panel>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                            Text="更新"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="取消"></asp:LinkButton>
                    <