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

assigning grid view hyper link button command argument

4 Answers 672 Views
Grid
This is a migrated thread and some comments may be shown as answers.
usman
Top achievements
Rank 1
usman asked on 01 Feb 2012, 09:50 PM

<
telerik:RadGrid ID="RadGrid1" runat="server" Skin="Sitefinity"
           onitemcommand="RadGrid1_ItemCommand"
           onitemdatabound="RadGrid1_ItemDataBound1" >
           
       <MasterTableView AutoGenerateColumns="false" GridLines="None">
        <Columns>
        
       <telerik:GridButtonColumn DataTextField="firstname" UniqueName="col1" ButtonType="LinkButton" CommandName="detail"></telerik:GridButtonColumn>
         
        </Columns>
         
     
     
</MasterTableView>
 
           <HeaderContextMenu EnableAutoScroll="True">
           </HeaderContextMenu>
 
       </telerik:RadGrid

Now I want to assign the command argument of GridButtonColumn   with id(pk) from my db table,

so that every row is corresponding to an id which I can access later withour shpwng on the grid view 

4 Answers, 1 is accepted

Sort by
0
usman
Top achievements
Rank 1
answered on 01 Feb 2012, 10:24 PM
I tried another approach but got errors ,I wrote this code 

'<telerik:GridButtonColumn DataTextField="firstname" UniqueName="col1" ButtonType="LinkButton" CommandName="detail" CommandArgument= '<%#Eval("MemberID") %>' ></telerik:GridButtonColumn>'
I got these 2 errors 
'Error 20 Databinding expressions are only supported on objects that have a DataBinding event. Telerik.Web.UI.GridButtonColumn does not have a DataBinding event. Line   43'


'Error 21 Literal content ('</telerik:GridButtonColumn>') is not allowed within a 'Telerik.Web.UI.GridColumnCollection'.  Line 45'

0
Shinu
Top achievements
Rank 2
answered on 02 Feb 2012, 05:06 AM
Hello Usman,

Try the following code to access the ButtonColumn and assign CommandArgument.
c#:
protected void RadGrid1_ItemDataBound1(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
    LinkButton btn = (LinkButton)item["col1"].Controls[0];
    btn.CommandArgument=//assign the argument here
    }
}

-Shinu
0
usman
Top achievements
Rank 1
answered on 02 Feb 2012, 08:32 AM
Thanks Shinu , one thing more please , I wrote this grid view in one tab , I want that after assigning of command argument and taking it back from ItemClick event i want to open the other tab ,thanks
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Feb 2012, 09:30 AM
Hello,

<MasterTableView DataKeyNames="ID" Name="Parent" HierarchyLoadMode="Client">
              <Columns>
              <telerik:GridButtonColumn DataTextField="firstname" UniqueName="col1" ButtonType="LinkButton" CommandName="detail"></telerik:GridButtonColumn>
        
 
                  
                  <telerik:GridBoundColumn DataField="Name" UniqueName="Name">
                  </telerik:GridBoundColumn>
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            GridDataItem item = e.Item as GridDataItem;
 
            // using columnuniquename
            string str1 = item["Name"].Text;
 
            // using DataKey
            string str2 = item.GetDataKeyValue("ID").ToString();
 
 
            //RadTabStrip RadTabStrip1 = new RadTabStrip();
            //RadMultiPage RadMultiPage1 = new RadMultiPage();
            RadTabStrip1.SelectedIndex = 2;
            RadMultiPage1.SelectedIndex = 2;
        }
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
usman
Top achievements
Rank 1
Answers by
usman
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or