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

Extract data from columns

4 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Debashis Pyne
Top achievements
Rank 1
Debashis Pyne asked on 02 Feb 2011, 12:05 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Feb 2011, 12:28 PM
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.
0
Debashis Pyne
Top achievements
Rank 1
answered on 02 Feb 2011, 12:56 PM
Hi Shinu,

Thanks for your feedback.

The link you provided doesn't work.

Could you resend the same?

Thanks,
Debashis
0
Debashis Pyne
Top achievements
Rank 1
answered on 02 Feb 2011, 01:13 PM
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
0
Shinu
Top achievements
Rank 2
answered on 03 Feb 2011, 08:37 AM
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.
Tags
Grid
Asked by
Debashis Pyne
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Debashis Pyne
Top achievements
Rank 1
Share this question
or