Mahesh Babu Immedisetty
Top achievements
Rank 1
Mahesh Babu Immedisetty
asked on 29 Aug 2009, 06:12 AM
Hi,
I have a radGrid to which I am adding GridButtonColumn of type link at runtime. When I click on that link, it is calling my code behind item command. I am able to retrive text and index from GridCommandEventArgs. I want to know how to get the header text that this link is clicked.
Please provide me some solution.
protected void radGrid_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandSource.ToString() == "Telerik.Web.UI.GridLinkButton")
{
LinkButton lb = (LinkButton)e.CommandSource;
string text = lb.Text;
int index = e.Item.DataSetIndex;
}
}
Thanks,
Mahesh
I have a radGrid to which I am adding GridButtonColumn of type link at runtime. When I click on that link, it is calling my code behind item command. I am able to retrive text and index from GridCommandEventArgs. I want to know how to get the header text that this link is clicked.
Please provide me some solution.
protected void radGrid_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandSource.ToString() == "Telerik.Web.UI.GridLinkButton")
{
LinkButton lb = (LinkButton)e.CommandSource;
string text = lb.Text;
int index = e.Item.DataSetIndex;
}
}
Thanks,
Mahesh
6 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 31 Aug 2009, 06:28 AM
Hi Mahesh,
I hope you are trying to access the HeaderText of the Button column on clicking the LinkButton. If so try the following approach and see whether it helps.
CS:
Regards
Princy
I hope you are trying to access the HeaderText of the Button column on clicking the LinkButton. If so try the following approach and see whether it helps.
CS:
| protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == "MyCommand") |
| { |
| GridItem[] header = RadGrid2.MasterTableView.GetItems(GridItemType.Header); |
| GridHeaderItem headerItem = (GridHeaderItem)header[0]; |
| string strTxt = ((LinkButton)headerItem["BtnCol"].Controls[0]).Text; |
| } |
| } |
Regards
Princy
0
Mahesh Babu Immedisetty
Top achievements
Rank 1
answered on 31 Aug 2009, 06:54 AM
Thanks for the response Princy.
I am having some issue with the code that you supplied. Looks like I am missing something here. I am getting the following exception while trying to get the header text.
Cannot find a cell bound to column name 'Name'
I am adding column to radGrid -> MasterTableView as this:
GridButtonColumn gc1 = new GridButtonColumn();
gc1.DataTextField = "Name";
gc1.HeaderText = "Name";
gc1.CommandName = "Name";
gc1.ButtonType = GridButtonColumnType.LinkButton;
I am trying to access the value like this:
protected void radGrid_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Name")
{
GridItem[] header = radGrid.MasterTableView.GetItems(GridItemType.Header);
GridHeaderItem headerItem = (GridHeaderItem)header[0];
string strTxt = ((LinkButton)headerItem["Name"].Controls[0]).Text;
}
}
Am I missing something here??
Please help.
Thanks,
Mahesh
0
Mahesh Babu Immedisetty
Top achievements
Rank 1
answered on 31 Aug 2009, 07:06 AM
I got it. I forgot to set UniqueName property.
Thanks a lot Princy for your help.
0
Mahesh Babu Immedisetty
Top achievements
Rank 1
answered on 31 Aug 2009, 09:14 AM
I am facing issue when I am adding GridColumns in Page_Load. I am getting e.CommandName as empty in radGrid_ItemCommand method.
If I create columns in Page_Init() everything is going fine.
I want to add columns only when my page is loaded successfully.
Please help.
Mahesh
0
Mahesh Babu Immedisetty
Top achievements
Rank 1
answered on 31 Aug 2009, 09:35 AM
I think I want to be clear on my requirement.
I have a radGrid in which there are two link columns( Lets take RollNO and Name). User can click on any link. Now, I want to know which GridButtonColumn he clicked.
The way that you have suggested can give me header text only when I know the button column name. This way I can get the header text but I dont whether the user clicked RollNo or Name.
Please suggest some workaround.
Mahesh
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Aug 2009, 09:54 AM
Hi Mahesh,
Give a try with the following approach and see whether it is helpful.
CS:
Thanks
Shinu
Give a try with the following approach and see whether it is helpful.
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem item = (GridDataItem)e.Item; |
| LinkButton linkBtn1 = (LinkButton)item["RollNO"].Controls[0]; |
| linkBtn1.CommandArgument = "RollNO"; |
| LinkButton linkBtn2 = (LinkButton)item["Name"].Controls[0]; |
| linkBtn2.CommandArgument = "Name"; |
| } |
| } |
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandSource.ToString() == "Telerik.Web.UI.GridLinkButton") |
| { |
| string columnName = e.CommandArgument.ToString(); |
| } |
| } |
Thanks
Shinu