Selected items' values always return null

7 posts, 0 answers
  1. Ugur
    Ugur avatar
    7 posts
    Member since:
    Jul 2010

    Posted 08 Apr 2013 Link to this post

    Hi,

    When i want to get radgrid selected items, I show that all the cells' values are null. I applied the solutions below but they didn't work.

    Please help for getting selected row values.

    *******
      GridDataItem[] itemm = grdWorkReport.MasterTableView.GetSelectedItems();
            string ss = itemm[0]["CalismaTarihi"].Text;   ( --->>> ss  Returns null )

    ******
     foreach (GridDataItem item in grdWorkReport.SelectedItems)
            {
                Response.Write(item["CalismaTarihi"].Text.ToString()); // CustomerID is the uniquename of column 
            }
    *******

    My radgrid is :

      <telerik:RadGrid ID="grdWorkReport" Skin="Sitefinity" runat="server" AllowPaging="True"   SelectedItemStyle-BackColor="Orange"
                AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="350px" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound"
                Width="100%" ShowStatusBar="True" GroupingEnabled="False" AllowSorting="True"
                PageSize="10" AllowCustomPaging="True" OnItemCommand="RadGrid1_ItemCommand"  SortingSettings-SortToolTip="Sıralamak için buraya basınız." AllowMultiRowSelection="true">
                <PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat="{4} {1} sayfada {5} kayıt"
                    FirstPageToolTip="İlk Sayfa" LastPageToolTip="Son Sayfa" PrevPageToolTip="Önceki Sayfa"
                    NextPageToolTip="Sonraki Sayfa" />
                <ClientSettings>
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                    </ClientSettings>
                <MasterTableView CommandItemDisplay="Top" AllowFilteringByColumn="false" AllowCustomSorting="true"
                    Width="100%">
                    <CommandItemSettings ShowExportToWordButton="false" ShowExportToExcelButton="true"
                        ShowExportToCsvButton="false" ShowAddNewRecordButton="false" 
                        ExportToExcelText="Excel'e Aktar" />
                    <CommandItemStyle Height="30px" />
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
               
                    <Columns>

                       <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                    <ItemTemplate>
                      <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="ToggleRowSelection"
                        AutoPostBack="True" />
                    </ItemTemplate>
                    <HeaderTemplate>
                      <asp:CheckBox ID="headerChkbox" runat="server" OnCheckedChanged="ToggleSelectedState"
                        AutoPostBack="True" />
                    </HeaderTemplate>
                  </telerik:GridTemplateColumn>

                     <telerik:GridTemplateColumn UniqueName="RecordId" HeaderText="Kayıt ID" DataField="RecordId"
                             ReadOnly="true" Visible="false">
                            <ItemTemplate>
                                <asp:Label ID="lblRecordId" runat="server" Text='<%# Eval("RecordId") %>'></asp:Label>
                            </ItemTemplate>
                         
                        </telerik:GridTemplateColumn> 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Apr 2013 Link to this post

    Hi Ugur,

    Unfortunately I couldn't replicate the issue. Here is the sample code snippet I tried  to get the text of  a cell  in a selected row on a button click event . I guess the column you are accessing is a GridBoundColumn.

    ASPX:
    <telerik:RadGrid ID="grdWorkReport" runat="server" AllowPaging="True" PageSize="5"
        Skin="Hay" DataSourceID="SqlDataSource1" AllowMultiRowSelection="true" AutoGenerateColumns="false">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" UniqueName="CalismaTarihi">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="ToggleRowSelection"
                            AutoPostBack="True" />
                    </ItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="headerChkbox" runat="server" OnCheckedChanged="ToggleSelectedState"
                            AutoPostBack="True" />
                    </HeaderTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView></telerik:RadGrid>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />

    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach(GridDataItem item  in grdWorkReport.SelectedItems)
        {
            string Selected = item["CalismaTarihi"].Text.ToString();
        }
    }

    Please elaborate the scenario if it doesn't help.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ugur
    Ugur avatar
    7 posts
    Member since:
    Jul 2010

    Posted 08 Apr 2013 Link to this post

    Hi Princy,

    Thank you for your answer but it didn't  work for me. The columns are GridTemplateColumn and first i select a row, then click a button to get selected column values.

    My gridview and C# codes are above. 


  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 08 Apr 2013 Link to this post

    Hello,

    Please try with the below code snippet.

    <ClientSettings>
                  <Selecting AllowRowSelect="true" />
              </ClientSettings>

    protected void ToggleRowSelection(object sender, EventArgs e)
        {
            CheckBox chk = sender as CheckBox;
            GridDataItem item = chk.NamingContainer as GridDataItem;
            item.Selected = chk.Checked;
        }


    Thanks,
    Jayesh Goyani
  6. Ugur
    Ugur avatar
    7 posts
    Member since:
    Jul 2010

    Posted 08 Apr 2013 Link to this post

    Thank you. I solved.

    It is very easy actually. 

    To get values I must use item.FindControl() and get the value. Because i use GridTemplateColumn.

    Label lblid = item.FindControl("lblid") as Label

    lblid.Text = ....

    like this.
  7. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 13 May 2014 in reply to Jayesh Goyani Link to this post

    Hi,

       When i select a row in radgrid i am able to get the seleteditems[0].But when i select another row(2nd time) seleteditems[0] getting index out of range or index must be non negitive.I am using databind to bind the grid

    /Bharath
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 May 2014 in reply to bharath Link to this post

    Hi Bharath,

    You can try the following code snippet to get the selected rows values:

    ASPX:
    <MasterTableView DataKeyNames="OrderID">
      <ClientSettings EnablePostBackOnRowClick="true" Selecting-AllowRowSelect="true"> </ClientSettings>

    C#:
    protected void RadGrid1_SelectedIndexChanged1(object sender, EventArgs e)
    {
     foreach (GridDataItem selectedItem in RadGrid1.SelectedItems)
     {     
      string value = selectedItem.GetDataKeyValue("OrderID").ToString(); //Get the selected row datakey value
     }
    }

    Thanks,
    Shinu
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017