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

RadGrid GridTemplateColumn Click Value

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mahesh Babu
Top achievements
Rank 1
Mahesh Babu asked on 25 Aug 2009, 07:32 AM
Hi,

I have a RadGrid to which I am adding GridTemplateColumns at runtime. I am have label,link and checkbox ITemplate's which I am giving to GridTemplateColumns. I am able to generate links on the RadGrid successfully. But, I want to perform postback operation when I click on these links. I added runat server attribute to the linkbuttton which is causing a postback. I am able to understand that it is a postback from my generate link button using __EVENTARGET property.

My issue is I am not able to find the text of the link button to which this postback is happend. I checked __EVENTARGUMENT property but of no use.

Is there anyway to find this???


Thanks,
Mahesh

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 25 Aug 2009, 10:17 AM
Hello Mahesh Babu,

Have you tried casting the " sender " to the control class and accessing the Text property for the object, in LinkButton_Click event?

C#:
 
void Lbutton_Click(object sender, EventArgs e) 
    LinkButton lbtn = (LinkButton)sender; 
    String str = lbtn.Text; 

-Shinu.
0
Mahesh Babu
Top achievements
Rank 1
answered on 25 Aug 2009, 11:46 AM
I am building link columns using the below ITemplate class. I am not giving any click event, as somehow it is calling the event method. So, I tried giving nothing which result in postback but not calling any methhod. in page load using __EVENTTARGET, I am finding that its a link event. But I am not able to see the link text to which this click is happening. I hope I am clear.


 public class LinkTemplate : ITemplate
    {
        public string DataField { get; set; }
        public string DataFormat { get; set; }
        public string DataKey { get; set; }
        public string DataValue { get; set; }

        private LinkTemplate()
        {
        }

        public LinkTemplate(string dataField,string dataFormat, string dataKey, string dataValue)
        {
            DataField = dataField;
            DataFormat = dataFormat;
            DataKey = dataKey;
            DataValue = dataValue;
        }

        #region ITemplate Members

        public void InstantiateIn(Control container)
        {
            LinkButton hyperlink = new LinkButton();
            hyperlink.DataBinding += new EventHandler(LinkButton_DataBinding);
            container.Controls.Add(hyperlink);
        }

        void LinkButton_DataBinding(object sender, EventArgs e)
        {
            LinkButton linkButton = (LinkButton)sender;
            GridDataItem container = (GridDataItem)linkButton.NamingContainer;
            if(DataKey!=string.Empty&&DataValue!=string.Empty)
                linkButton.PostBackUrl = GetNavigationURL(container);
            if(DataFormat==string.Empty)
                linkButton.Text = ((DataRowView)container.DataItem)[DataField].ToString();
            else
                linkButton.Text = string.Format(DataFormat, ((DataRowView)container.DataItem)[DataField].ToString());
            linkButton.ID = string.Format("{0}{1}",Constants.RFGeneratedLinkButton , new Random().Next());
            
            
        }

        private string GetNavigationURL(GridDataItem container)
        {
            string[] dataKeyValuesArray = DataValue.Split(',');
            string[] dataValuesArray = new string[dataKeyValuesArray.Length];
            for (int index = 0; index < dataValuesArray.Length; index++)
                dataValuesArray[index] = ((DataRowView)container.DataItem)[dataKeyValuesArray[index]].ToString();
            return string.Format(DataKey, dataValuesArray);
        }

        #endregion
    }
Tags
Grid
Asked by
Mahesh Babu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Mahesh Babu
Top achievements
Rank 1
Share this question
or