A
ABHIJIT B
Hi,
I am using datagrid in my PopUp window page.It has radio button for
selecting row.
I want to allow single selection at a time.I am able to solve problem
using belowcode.
Currently I am facing is I am allowing Paging for datagrid.
Now I am disabling Paging and allow scrolling.If I enable scrolling
and user selects 25 row.The PopUp window focus is not on 25 row it
shows first row.In this case row 25 is selected.The Popup window goes
up.
My problem is focus should be on selected row.Is this possible in
JavScript.
Kindly help me.
ASPX code:
<asp:datagrid id="dgADUserList" runat="server" Width="720px"
BackColor="White" AutoGenerateColumns="False" CellPadding="4"
Height="22px" BorderWidth="1px"
BorderStyle="None"
BorderColor="#CC9966" CssClass="listItems"> <%-- PageSize="5"
AllowPaging="true"> OnPageIndexChanged="dgADUserList_PageIndexChanged"
<asp:TemplateColumn
HeaderText="Select">
<ItemTemplate>
<asp:RadioButton
id="rdbSelect" runat="server" AutoPostBack="True"
OnCheckedChanged="SelectOnlyOne"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn
DataField="LoginName" SortExpression="LoginName"
HeaderText="LoginName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName" HeaderText="LastName"></
asp:BoundColumn>
</Columns>
<ItemStyle CssClass="row-1"
HorizontalAlign="Center" BorderColor="Black" ForeColor="Black" />
<SelectedItemStyle
BackColor="LightSkyBlue" ForeColor="Black" BorderStyle="Solid"
BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerStyle BackColor="#2461BF"
ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle"/>
<HeaderStyle BackColor="ButtonFace"
Font-Bold="True" ForeColor="Black" BorderColor="Black"
HorizontalAlign="Center" />
<AlternatingItemStyle CssClass="row-2"
BackColor="LightGray" />
</asp:datagrid>
..CS code:
public void SelectOnlyOne(object sender, EventArgs e)
{
string m_ClientID = "";
RadioButton rb = new RadioButton();
rb = (RadioButton)(sender);
m_ClientID = rb.ClientID;
foreach (DataGridItem i in dgADUserList.Items)
{
rb = (RadioButton)(i.FindControl("rdbSelect"));
rb.Checked = false;
if (m_ClientID == rb.ClientID)
{
rb.Checked = true;
}
//Get selected value
if (rb.Checked == true)
{
if (i.Cells[1].Text.Trim().ToString() == " ")
hidLoginID.Value = "";
else
hidLoginID.Value =
i.Cells[1].Text.Trim().ToString();
if (i.Cells[2].Text.Trim().ToString() == " ")
hidFirstName.Value = "";
else
hidFirstName.Value =
i.Cells[2].Text.Trim().ToString();
if (i.Cells[3].Text.Trim().ToString() == " ")
hidLastName.Value = "";
else
hidLastName.Value =
i.Cells[3].Text.Trim().ToString();
}
}
}
Regards,
Abhijit B
I am using datagrid in my PopUp window page.It has radio button for
selecting row.
I want to allow single selection at a time.I am able to solve problem
using belowcode.
Currently I am facing is I am allowing Paging for datagrid.
Now I am disabling Paging and allow scrolling.If I enable scrolling
and user selects 25 row.The PopUp window focus is not on 25 row it
shows first row.In this case row 25 is selected.The Popup window goes
up.
My problem is focus should be on selected row.Is this possible in
JavScript.
Kindly help me.
ASPX code:
<asp:datagrid id="dgADUserList" runat="server" Width="720px"
BackColor="White" AutoGenerateColumns="False" CellPadding="4"
Height="22px" BorderWidth="1px"
BorderStyle="None"
BorderColor="#CC9966" CssClass="listItems"> <%-- PageSize="5"
AllowPaging="true"> OnPageIndexChanged="dgADUserList_PageIndexChanged"
<Columns>--%>
<asp:TemplateColumn
HeaderText="Select">
<ItemTemplate>
<asp:RadioButton
id="rdbSelect" runat="server" AutoPostBack="True"
OnCheckedChanged="SelectOnlyOne"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn
DataField="LoginName" SortExpression="LoginName"
HeaderText="LoginName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName" HeaderText="LastName"></
asp:BoundColumn>
</Columns>
<ItemStyle CssClass="row-1"
HorizontalAlign="Center" BorderColor="Black" ForeColor="Black" />
<SelectedItemStyle
BackColor="LightSkyBlue" ForeColor="Black" BorderStyle="Solid"
BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerStyle BackColor="#2461BF"
ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle"/>
<HeaderStyle BackColor="ButtonFace"
Font-Bold="True" ForeColor="Black" BorderColor="Black"
HorizontalAlign="Center" />
<AlternatingItemStyle CssClass="row-2"
BackColor="LightGray" />
</asp:datagrid>
..CS code:
public void SelectOnlyOne(object sender, EventArgs e)
{
string m_ClientID = "";
RadioButton rb = new RadioButton();
rb = (RadioButton)(sender);
m_ClientID = rb.ClientID;
foreach (DataGridItem i in dgADUserList.Items)
{
rb = (RadioButton)(i.FindControl("rdbSelect"));
rb.Checked = false;
if (m_ClientID == rb.ClientID)
{
rb.Checked = true;
}
//Get selected value
if (rb.Checked == true)
{
if (i.Cells[1].Text.Trim().ToString() == " ")
hidLoginID.Value = "";
else
hidLoginID.Value =
i.Cells[1].Text.Trim().ToString();
if (i.Cells[2].Text.Trim().ToString() == " ")
hidFirstName.Value = "";
else
hidFirstName.Value =
i.Cells[2].Text.Trim().ToString();
if (i.Cells[3].Text.Trim().ToString() == " ")
hidLastName.Value = "";
else
hidLastName.Value =
i.Cells[3].Text.Trim().ToString();
}
}
}
Regards,
Abhijit B