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>
The rowDataBound
Method is:
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);
}
}
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.
How can I achieve this?
You can check like...
if (GridView1.SelectedValue != null)
{
//Row is Selected
}
You can try something like this:
If GridView1.SelectedRows.Count > 0 Then
' yourcode here - a row is selected
Else
' yourcode here - NO row is selected
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With