如何检查是否有任何行从GridView的选择? [英] How to check if any row is selected from GridView?

查看:133
本文介绍了如何检查是否有任何行从GridView的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx页面的GridView:

I have a gridview in aspx page:

<asp:GridView ID="gdvMainList" runat="server" CssClass="Grid1" SkinID="PagedGridView"
                                    AutoGenerateColumns="false" OnRowDataBound="gdvMainList_RowDataBound"
                                    DataSourceId="dtsConsumers" Visible="false" DataKeyNames="Id">
                                    <Columns>
                                        <asp:CommandField SelectText="Select" ShowSelectButton="true" ItemStyle-CssClass="HideButton"
                                            HeaderStyle-CssClass="HideButton">
                                            <HeaderStyle CssClass="HideButton" />
                                            <ItemStyle CssClass="HideButton" />
                                        </asp:CommandField>
                                        <asp:TemplateField HeaderText="Name">
                                            <ItemTemplate>
                                                <span>
                                                    <%# Pc.PrecisionCare2.PL.Common.Utility.GetFullName("", Eval("LastName"), Eval("FirstName"), Eval("MiddleInit")) %></span>
                                            </ItemTemplate>
                                            <ItemStyle Width="200px" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status"></asp:BoundField>
                                    </Columns>
                                    <SelectedRowStyle CssClass="SelectedItem" BackColor="#c9e0ee" />
                                    <EmptyDataTemplate>
                                        <div class="divEmptyGrid">
                                            --- No Consumer Exists ---
                                        </div>
                                    </EmptyDataTemplate>
                                </asp:GridView>

的RowDataBound 方法是:

protected void gdvMainList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gdvMainList, "Select$" + e.Row.RowIndex);
            }
        }

我有一个OK按钮,点击它的时候,我从一个页面收集数据。我要检查OK按钮点击即有从GridView的或没有选择任何一行。

I have an OK button, when it is clicked, I collect data from page. I want to check on OK button click that is there any row selected from Gridview or not.

我怎样才能做到这一点?
任何帮助将是AP preciated。

How can I achieve this? Any help would be appreciated.

推荐答案

您可以检查像...

if (GridView1.SelectedValue != null)
{
     //Row is Selected
}

这篇关于如何检查是否有任何行从GridView的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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