This is a migrated thread and some comments may be shown as answers.

RadGrid Row Selection

1 Answer 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vijay Kartha
Top achievements
Rank 1
Vijay Kartha asked on 02 Feb 2009, 06:10 AM
Hi,
I'm using RadGrid 6.0 with Q3 2007 sp2.  When the textbox got selected or got the focus then the current row should be selected.

Please go through aspx code...
---------------------
<radg:RadGrid ShowFooter="True" ID="radLists" runat="server" AllowPaging="True" AllowSorting="True"
            GridLines="None" Skin="Default" 
            PageSize="15" EnableAJAXLoadingTemplate="True" LoadingTemplateTransparency="25" Width="100%" EnableAJAX="True" ShowStatusBar="True">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="PKey" CommandItemDisplay="TopAndBottom">
                <Columns>
                <rad:GridClientSelectColumn UniqueName="ClientSelectColumn" Visible="False"  />
                    <rad:GridTemplateColumn DataField="VoucherNumber" HeaderText="Voucher #" UniqueName="VoucherNumber">
                        <HeaderTemplate>
<asp:LinkButton id="lbVoucherNumber" runat="server" CssClass="Link" Text="Voucher #" CommandArgument="VoucherNumber" Font-Bold="True" Font-Underline="False" ForeColor="White" OnCommand="lbVoucherNumber_Command" BackColor="Transparent"></asp:LinkButton><BR /><asp:DropDownList id="rcmbVoucherNumber" runat="server" CssClass="ComboBox" AutoPostBack="True" OnSelectedIndexChanged="rcmbVoucherNumber_SelectedIndexChanged">
                            </asp:DropDownList><asp:ImageButton id="imgVoucherNumber" runat="server" ToolTip="Reset the Filter" ImageUrl="~/Images/action_refresh.gif" OnClick="imgVoucherNumber_Click"></asp:ImageButton>
</HeaderTemplate>
                        <ItemTemplate>
<asp:Label id="VoucherNumberLabel" runat="server" Text='<%# Eval("VoucherNumber") %>' ></asp:Label>
</ItemTemplate>
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn DataField="DueDate" HeaderText="Due Date" UniqueName="DueDate">
                        <EditItemTemplate>
<asp:TextBox id="DueDateTextBox" runat="server" Text='<%# Bind("DueDate", "{0:dd-MMM-yy}") %>' ></asp:TextBox>
</EditItemTemplate>
                          <HeaderTemplate>
<asp:LinkButton id="lbDueDate" runat="server" CssClass="Link" Text="Due Date" CommandArgument="DueDate" Font-Bold="True" Font-Underline="False" ForeColor="White" OnCommand="lbDueDate_Command" BackColor="Transparent"></asp:LinkButton><BR /><asp:DropDownList id="rcmbDueDate" runat="server" CssClass="ComboBox" AutoPostBack="True" OnSelectedIndexChanged="rcmbDueDate_SelectedIndexChanged">
                            </asp:DropDownList><asp:ImageButton id="imgDueDate" onclick="imgDueDate_Click" runat="server" ToolTip="Reset the Filter" ImageUrl="~/Images/action_refresh.gif"></asp:ImageButton>
</HeaderTemplate>
                        <ItemTemplate>
<asp:Label id="DueDateLabel" runat="server" Text='<%# Eval("DueDate", "{0:dd-MMM-yy}") %>'></asp:Label>
</ItemTemplate>
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn DataField="SubAccountName" HeaderText="Sub Acc Name" UniqueName="SubAccountName">
                        <EditItemTemplate>
<asp:TextBox id="SubAccountNameTextBox" runat="server" Text='<%# Bind("SubAccountName") %>' ></asp:TextBox>
</EditItemTemplate>
                          <HeaderTemplate>
<asp:LinkButton id="lbSubAccountName"  runat="server" CssClass="Link" Text="Sub Acc Name" OnCommand="lbSubAccountName_Command" ForeColor="White" Font-Underline="False" Font-Bold="True" CommandArgument="SubAccountName" BackColor="Transparent" ></asp:LinkButton><BR /><asp:DropDownList id="rcmbSubAccountName" runat="server" CssClass="ComboBox" AutoPostBack="True" Width="150px" OnSelectedIndexChanged="rcmbSubAccountName_SelectedIndexChanged" >
                            </asp:DropDownList><asp:ImageButton id="imgSubAccountName"  runat="server" ToolTip="Reset the Filter" ImageUrl="~/Images/action_refresh.gif" ></asp:ImageButton>
</HeaderTemplate>
                        <ItemTemplate>
<asp:Label id="SubAccountNameLabel" runat="server" Text='<%# Eval("SubAccountName") %>' ></asp:Label>
</ItemTemplate>
                        <HeaderStyle Width="150px" />
                        <ItemStyle Width="150px" />
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn DataField="Amount_FC" HeaderText="Amount" UniqueName="Amount_FC">
                          <HeaderTemplate>
                            <asp:LinkButton ID="lbAmount_FC" runat="server" BackColor="Transparent" CommandArgument="Amount_FC"
                                CssClass="Link" Font-Bold="True" Font-Underline="False" ForeColor="White" OnCommand="lbAmount_FC_Command"
                                Text="Amount" ></asp:LinkButton><br />
                            <asp:DropDownList ID="rcmbAmount_FC" runat="server" AutoPostBack="True" CssClass="ComboBox"
                                OnSelectedIndexChanged="rcmbAmount_FC_SelectedIndexChanged">
                            </asp:DropDownList><asp:ImageButton ID="imgAmount_FC" runat="server" ImageUrl="~/Images/action_refresh.gif"
                                OnClick="imgAmount_FC_Click" ToolTip="Reset the Filter" />
                       
</HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Amount_FCLabel" runat="server" Text='<%# Eval("Amount_FC", "{0:###,###,###,###.#0}") %>' ></asp:Label>
                       
</ItemTemplate>
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn DataField="BalanceAmount" HeaderText="Balance" UniqueName="BalanceAmount">
                        <EditItemTemplate>
                            <asp:TextBox ID="BalanceAmountTextBox" runat="server" Text='<%# Bind("BalanceAmount", "{0:###,###,###,###.#0}") %>'></asp:TextBox>
                       
</EditItemTemplate>
                          <HeaderTemplate>
                            <asp:LinkButton ID="lbBalanceAmount" runat="server" BackColor="Transparent" CommandArgument="BalanceAmount"
                                CssClass="Link" Font-Bold="True" Font-Underline="False" ForeColor="White" OnCommand="lbBalanceAmount_Command"
                                Text="Balance"></asp:LinkButton><br />
                            <asp:DropDownList ID="rcmbBalanceAmount" runat="server" AutoPostBack="True" CssClass="ComboBox"
                                OnSelectedIndexChanged="rcmbBalanceAmount_SelectedIndexChanged">
                            </asp:DropDownList><asp:ImageButton ID="imgBalanceAmount" runat="server" ImageUrl="~/Images/action_refresh.gif"
                                OnClick="imgBalanceAmount_Click" ToolTip="Reset the Filter" />
                       
</HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="BalanceAmountLabel" runat="server" Text='<%# Eval("BalanceAmount", "{0:###,###,###,###.#0}") %>'></asp:Label>
                       
</ItemTemplate>
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn DataField="CurrencyID" HeaderText="Ccy" UniqueName="CurrencyID">
                          <HeaderTemplate>
<asp:LinkButton id="lbCurrencyID" onclick="lbCurrencyID_Click" runat="server" CssClass="Link" Text="Ccy" BackColor="Transparent" CommandArgument="CurrencyID" Font-Bold="True" Font-Underline="False" ForeColor="White" OnCommand="lbSettledAmount_Command" ></asp:LinkButton><BR />
<asp:DropDownList id="rcmbCurrencyID" runat="server" CssClass="ComboBox" AutoPostBack="True" OnSelectedIndexChanged="rcmbCurrencyID_SelectedIndexChanged" >
                            </asp:DropDownList><asp:ImageButton id="imgCurrencyID" onclick="imgSettledAmount_Click" runat="server" ImageUrl="~/Images/action_refresh.gif" ToolTip="Reset the Filter" ></asp:ImageButton>
</HeaderTemplate>
                        <ItemTemplate>
<asp:Label id="lblCurrency" runat="server" Text='<%# Eval("CurrencyID") %>' ></asp:Label>
</ItemTemplate>
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn UniqueName="Template1" HeaderText="Amount FC" >
                       <footertemplate>
                       
</footertemplate>
                         <HeaderTemplate>
<asp:LinkButton id="lblAmountFC" runat="server" CssClass="Link" Text="Amount FC" BackColor="Transparent" OnCommand="lblAmountFC_Command" ForeColor="White" Font-Underline="False" Font-Bold="True" CommandArgument="Amount_FC" Enabled="False" ></asp:LinkButton>
</HeaderTemplate>
                        <ItemTemplate>
<radi:RadNumericTextBox id="txtCurrentPayment" runat="server" AutoPostBack="True" Width="100px" CausesValidation="True" DbValue='<%# Eval("CurrentPayment") %>' Culture="English (United States)" LabelCssClass="radLabelCss_Default" OnTextChanged="txtCurrentPayment_TextChanged" >
<IncrementSettings InterceptArrowKeys="False" InterceptMouseWheel="False"></IncrementSettings>

<ClientEvents OnFocus="Focus"></ClientEvents>

<NumberFormat AllowRounding="True" DecimalDigits="3"></NumberFormat>
</radi:RadNumericTextBox> <radi:RadNumericTextBox id="rntExchangeRate" runat="server" Width="100px" Visible="False" Skin="" DbValue='<%# Eval("ExchangeRate") %>' Culture="English (United States)" LabelCssClass="radLabelCss_Default" OnTextChanged="txtCurrentPayment_TextChanged" >
<IncrementSettings InterceptArrowKeys="False" InterceptMouseWheel="False"></IncrementSettings>

<NumberFormat AllowRounding="True" DecimalDigits="3"></NumberFormat>
</radi:RadNumericTextBox>
</ItemTemplate>
                        <HeaderStyle Width="100px" />
                        <ItemStyle Width="100px" />
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn HeaderText="Amount LC"
                        UniqueName="CurrentPayment_BC">
                          <HeaderTemplate>
<asp:LinkButton id="lblAmountLC" runat="server" CssClass="Link" Text="Amount LC" Enabled="False" CommandArgument="Amount_BC" Font-Bold="True" Font-Underline="False" ForeColor="White" OnCommand="lblAmountBC_Command" BackColor="Transparent"></asp:LinkButton>
</HeaderTemplate>
                        <ItemTemplate>
<radi:RadNumericTextBox id="txtCurrentPaymentBC" runat="server" Width="100px" OnTextChanged="txtCurrentPaymentBC_TextChanged" LabelCssClass="radLabelCss_Default" Culture="English (United States)" DbValue='<%# Eval("CurrentPayment") %>' >
<IncrementSettings InterceptArrowKeys="False" InterceptMouseWheel="False"></IncrementSettings>

<NumberFormat AllowRounding="True" DecimalDigits="3"></NumberFormat>
</radi:RadNumericTextBox>
</ItemTemplate>
                    </rad:GridTemplateColumn>
                        <rad:GridTemplateColumn UniqueName="Template2" >
                                                    <ItemTemplate>
<asp:LinkButton id="lbPaythis" onclick="lbPaythis_Click" runat="server" Width="50px" CommandArgument='<%# Bind("PKey") %>' CommandName="Select">Pay this</asp:LinkButton>
</ItemTemplate>
                                        <footerstyle verticalalign="Middle" horizontalalign="Right" wrap="False" />
                                        <HeaderStyle verticalalign="Middle" horizontalalign="Right" wrap="False" />
                                        <ItemStyle horizontalalign="Right" wrap="False" />
                                    </rad:GridTemplateColumn>
                                </Columns>
                                <RowIndicatorColumn Visible="False">
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn Resizable="False" Visible="False">
                                    <HeaderStyle Width="20px" />
                                </ExpandCollapseColumn>
                <CommandItemTemplate>
                    <table class="MainTable" style="height: 55%" width="100%">
                        <tr>
                            <td align="right" colspan="5" style="width: 95%" valign="top">
                                <asp:Button ID="btnPayAll" runat="server" CssClass="Button" OnClick="btnPayAll2_Click"
                                    Text="Pay All" Width="80px" />
                                &nbsp; &nbsp;
                            </td>
                            <td valign="top">
                                <asp:ImageButton ID="btnSave2" runat="server" BackColor="WhiteSmoke" BorderColor="WhiteSmoke"
                                    BorderStyle="Solid" BorderWidth="3px" CssClass="IconButton" ImageUrl="~/Images/Save.ico"
                                    OnClick="btnSave2_Click" ToolTip="Save" />
                            </td>
                            <td valign="top">
                                <asp:ImageButton ID="btnUndo2" runat="server" BackColor="WhiteSmoke" BorderColor="WhiteSmoke"
                                    BorderStyle="Solid" BorderWidth="3px" ImageUrl="~/Images/Undo.ico" OnClick="btnUndo2_Click"
                                    ToolTip="Undo" />
                            </td>
                        </tr>
                    </table>
                </CommandItemTemplate>
                            </MasterTableView>
                            <ClientSettings AllowKeyboardNavigation="True" >
                                <Selecting AllowRowSelect="True" />
                                <ClientEvents OnActiveRowChanged="ActiveRowChanged"  OnGridCreated="GridCreated" OnActiveRowChanging="ActiveRowChanging" OnRowMouseOver="RowMouseOver" OnRowSelected="RowSelected" />
                            </ClientSettings>
                        </radg:RadGrid>





1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Feb 2009, 08:12 AM
Hello Vijay,

Check out the following code to select an item on setting the focus on a textbox control in the grid:
aspx:
 <radG:GridTemplateColumn> 
        <ItemTemplate> 
            <asp:TextBox ID="TextControl" runat="server"></asp:TextBox> 
        </ItemTemplate> 
 </radG:GridTemplateColumn>   

cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            int index = dataItem.ItemIndex; 
            TextBox txtbx = (TextBox)dataItem.FindControl("TextControl"); 
            txtbx.Attributes.Add("OnFocus", "return selectitem('" + index + "');"); 
        } 
    } 

js:
function selectitem(index)  
   {      
        var grid = window["<%= RadGrid1.ClientID %>"]; 
        var rows = grid.MasterTableView.Rows;        
        rows[index].SetSelected(true); 
   }  

Thanks
Princy.
Tags
Grid
Asked by
Vijay Kartha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or