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

Grid and Button Problems

4 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Iron
Todd asked on 30 Mar 2011, 08:07 PM
First let me specify my environment, am using the ASP.net AJAX Q1 2011 35 controls in VS2010 with VB.net.

I am trying to bind a RadGrid to a dataset allowing it to autogenerate the columns, then set the format of the columns in code in the itemdatabound event.  I prefer this way because it allows me to just set header text and width without having to define every property of every column in code.  I also have a need to add a button to a column.  I am adding the button in the page_load event in the mastertableview and it shows up properly when the page loads, but when I click on the button the grid refreshes and the button disappears.  So first I need to be able to keep the button from disappearing, and second I'm not sure how I can put code in the button click event.

I would appreciate any help that anyone can provide.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Mar 2011, 06:54 AM
Hello,

Try adding the control in GridItemCreated vent and attach the event. Here is a sample code to achieve the same.
C#:
protected void grdEmail_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        
      GridDataItem item = (GridDataItem)e.Item;
      Button btn1 = new Button();
      btn1.Text = "Hai";
      btn1.Click += new EventHandler(btn1_Click);//attatching the event OnClick
      item["rutaShp"].Controls.Add(btn1);
         }
      }
 void btn1_Click(object sender, EventArgs e)//Handler for OnClick
    {
        
    }

Thanks,
Shinu.
0
Todd
Top achievements
Rank 1
Iron
answered on 31 Mar 2011, 03:12 PM
So is it possible to get a true Button control in a grid column without adding it in the page_load as a gridbuttoncolumn?
0
Pavlina
Telerik team
answered on 06 Apr 2011, 09:14 AM
Hi Todd,

Can you please verify that you tried the approach suggested by Shinu and it is not working for you?

Regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Todd
Top achievements
Rank 1
Iron
answered on 06 Apr 2011, 12:57 PM
I did try it actually and it worked, I was just asking a follow up question.  I will now mark that answer as correct.
Tags
Grid
Asked by
Todd
Top achievements
Rank 1
Iron
Answers by
Shinu
Top achievements
Rank 2
Todd
Top achievements
Rank 1
Iron
Pavlina
Telerik team
Share this question
or