A
ABHIJIT B
Hi,
I am using GridView control in one of my ASPNET 2.0 web page.
The problem I am facing is GridView should allow only single row
selection only.
Aslo I want to know How I can do sam eusing Radio/Option button.
Thanks in Advance
<asp:GridView ID="gvSearchUsersList" runat="server" TabIndex="5"
PageSize="5" AllowPaging="True" AutoGenerateColumns="False"
OnPageIndexChanging="gvSearchUsersList_PageIndexChanging"
AllowSorting="True" GridLines="None" Width="717px"
ForeColor="#333333">
<Columns>
<asp:TemplateField
HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect"
AutoPostBack="true" runat="server"
OnCheckedChanged="chkSelect_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LoginName"
HeaderText="Login Name" />
<asp:BoundField DataField="FirstName"
HeaderText="First Name" />
<asp:BoundField DataField="LastName"
HeaderText="Last Name" />
</Columns>
<PagerSettings
Mode="NextPreviousFirstLast" />
<RowStyle CssClass="row-1"
HorizontalAlign="Center" />
<SelectedRowStyle
BackColor="InactiveCaptionText" ForeColor="Black" BorderStyle="Solid"
BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerStyle BackColor="#2461BF"
ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle"/>
<HeaderStyle BackColor="#507CD1" Font-
Bold="True" ForeColor="Black" />
<AlternatingRowStyle CssClass="row-2"
BackColor="LightGray" />
</asp:GridView>
---------------------------------------------------
From .cs file I am binding rows to GridView as given below,
gvSearchUsersList.DataSource = dtSearchUserList;
gvSearchUsersList.DataBind();
dcSearchSucess = true;
I am getting selected row value as given below,
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
try
{
CheckBox checkbox = (CheckBox)sender;
GridViewRow row = (GridViewRow)checkbox.NamingContainer;
if (checkbox.Checked == true)
{
Session["dcSelectedLoginID"] = null;
Session["dcSelectedLoginID"] =
row.Cells[1].Text.Trim().ToString();
hidLoginID.Value =
row.Cells[1].Text.Trim().ToString();
}
}
catch (Exception ex)
{
TraceSUError.Log("Exception occurred : " + ex.Message);
return;
}
}
I am using GridView control in one of my ASPNET 2.0 web page.
The problem I am facing is GridView should allow only single row
selection only.
Aslo I want to know How I can do sam eusing Radio/Option button.
Thanks in Advance
<asp:GridView ID="gvSearchUsersList" runat="server" TabIndex="5"
PageSize="5" AllowPaging="True" AutoGenerateColumns="False"
OnPageIndexChanging="gvSearchUsersList_PageIndexChanging"
AllowSorting="True" GridLines="None" Width="717px"
ForeColor="#333333">
<Columns>
<asp:TemplateField
HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect"
AutoPostBack="true" runat="server"
OnCheckedChanged="chkSelect_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LoginName"
HeaderText="Login Name" />
<asp:BoundField DataField="FirstName"
HeaderText="First Name" />
<asp:BoundField DataField="LastName"
HeaderText="Last Name" />
</Columns>
<PagerSettings
Mode="NextPreviousFirstLast" />
<RowStyle CssClass="row-1"
HorizontalAlign="Center" />
<SelectedRowStyle
BackColor="InactiveCaptionText" ForeColor="Black" BorderStyle="Solid"
BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerStyle BackColor="#2461BF"
ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle"/>
<HeaderStyle BackColor="#507CD1" Font-
Bold="True" ForeColor="Black" />
<AlternatingRowStyle CssClass="row-2"
BackColor="LightGray" />
</asp:GridView>
---------------------------------------------------
From .cs file I am binding rows to GridView as given below,
gvSearchUsersList.DataSource = dtSearchUserList;
gvSearchUsersList.DataBind();
dcSearchSucess = true;
I am getting selected row value as given below,
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
try
{
CheckBox checkbox = (CheckBox)sender;
GridViewRow row = (GridViewRow)checkbox.NamingContainer;
if (checkbox.Checked == true)
{
Session["dcSelectedLoginID"] = null;
Session["dcSelectedLoginID"] =
row.Cells[1].Text.Trim().ToString();
hidLoginID.Value =
row.Cells[1].Text.Trim().ToString();
}
}
catch (Exception ex)
{
TraceSUError.Log("Exception occurred : " + ex.Message);
return;
}
}