Extract data from columns

5 posts, 1 answers
  1. Debashis Pyne
    Debashis Pyne avatar
    66 posts
    Member since:
    Apr 2010

    Posted 02 Feb 2011 Link to this post

    Hi,

    I have the following radgrid integrated to my application.

    <telerik:RadGrid ID="grdCompanyList"
                    runat="server" GridLines="None"
                    AutoGenerateColumns="False"
                    AllowSorting="True"
                    AllowFilteringByColumn = "True"
                    AllowPaging="True"
                    EnableLinqExpressions="False"
                    PageSize="10"
                    OnNeedDataSource="grdCompanyList_NeedDataSource"
                    OnItemCreated="grdCompanyList_ItemCreated">
                     
                    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>                               
                    <MasterTableView DataKeyNames="watchlist_id" CommandItemDisplay="Top" EditMode="PopUp">
                    <CommandItemSettings ShowAddNewRecordButton="false"/>
                    <Columns>
     
                        <telerik:GridBoundColumn DataField="watchlist_id" DataType="System.Int32"
                            HeaderText="watchlist_id" ReadOnly="True" SortExpression="watchlist_id"
                            UniqueName="watchlist_id" Visible="false" >
                        </telerik:GridBoundColumn>
                         
                        <telerik:GridBoundColumn DataField="company_id" DataType="System.Int32"
                            HeaderText="company_id" ReadOnly="True" SortExpression="company_id"
                            UniqueName="company_id" Visible="false" >
                        </telerik:GridBoundColumn>
                         
                        <telerik:GridTemplateColumn AllowFiltering="false" ItemStyle-Width="180px">
                        <ItemTemplate>
                            <asp:Image width="142" height="58" ID="CompLogos" ImageUrl="<%# showCompLogo(Container.DataItem) %>"
                             runat="server" AlternateText="Logo" />
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                         
                        <telerik:GridBoundColumn DataField="company_name"
                            HeaderText="Company name" SortExpression="company_name" ItemStyle-Width="450"
                            UniqueName="company_name" ReadOnly="true">
                            <ItemStyle Width="450px" />
                        </telerik:GridBoundColumn>                  
                       
                        <telerik:GridTemplateColumn AllowFiltering="false" ItemStyle-Width="50px">
                        <ItemTemplate>
                            <asp:HyperLink ID="CoLink"  runat="server" Text="Edit" ImageUrl="~/images/viewicon_big.png" ToolTip="View Details"></asp:HyperLink>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>                  
     
                    </Columns>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true"></ClientSettings>
                    </telerik:RadGrid>
     
    I need to extract the company ids which is in the second column in the grid and use that to redirect to a different page.
    I have used the following code:

    protected void grdCompanyList_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               HyperLink CoLink = (HyperLink)e.Item.FindControl("CoLink");
               GridDataItem item = (GridDataItem)e.Item;
               string Cid = item["company_id"].Text;
               CoLink.Attributes["href"] = "CompanyDetails.aspx?Id=" + Cid;
           }
       }

    However the above doesn't work.

    Please suggest I can i extract the data from the seconds column.

    Thanks,

    Debashis

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Feb 2011 Link to this post

    Hello Debashis,

    ItemCreated
    is fired before the item is data-bound. Thus no data is still in the cells' text or input controls. In ItemDataBound all is available.
    so try the same code in ItemDataBound Event instead of ItemCreatedEvent.

    Also check the following documentation.
    Distinguishing the major differences between ItemCreated and ItemDataBound events

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Debashis Pyne
    Debashis Pyne avatar
    66 posts
    Member since:
    Apr 2010

    Posted 02 Feb 2011 Link to this post

    Hi Shinu,

    Thanks for your feedback.

    The link you provided doesn't work.

    Could you resend the same?

    Thanks,
    Debashis
  5. Debashis Pyne
    Debashis Pyne avatar
    66 posts
    Member since:
    Apr 2010

    Posted 02 Feb 2011 Link to this post

    Hi Shinu

    I now have a new column as below:

    <telerik:GridTemplateColumn AllowFiltering="false" ItemStyle-Width="50px">
                        <ItemTemplate>
                            <asp:HyperLink ID="CoLink"  runat="server" Text="Edit" ImageUrl="~/images/viewicon_big.png" ToolTip="View Details"></asp:HyperLink>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>

    Can you please suggest how can I add this to the ItemBound method?

    Thanks,

    Debashis
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2011 Link to this post

    Hello Debashis,

    Try the following code snippet in ItemDataBound event.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               HyperLink CoLink = (HyperLink)e.Item.FindControl("CoLink");
               GridDataItem item = (GridDataItem)e.Item;
               string Cid = item["company_id"].Text;
               CoLink.Attributes["href"] = "CompanyDetails.aspx?Id=" + Cid;
           }
       }

    And check out this documentation.
    http://www.telerik.com/help/aspnet-ajax/grddistinguishdifferencesbetweenitemcreateditemdatabound.html

    Hope this helps,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017