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

[Solved] Item command Problem in Autogenerate Column Grid

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 17 Apr 2013, 12:45 PM
Hello,

I am using rad Grid with Auto generated columns.
I am adding Link Button at ItemDatabound Event.  so rows will generated as link button cell.
Now Problem is that  When I click on linkbutton that does not fire ItemCommand Event and convert cell in Normal Cell.
Link button removed after click on it.
So What is problem?
 and
Please Give me Solution.

Thanks....

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Apr 2013, 01:01 PM
Hi,

Please try the same code for adding the LinkButton in the ItemCreated event as well, that is, add the control in ItemDataBound and recreate this control if needed on ItemCreated for subsequent postbacks.

Thanks,
Princy.
0
Ajay
Top achievements
Rank 1
answered on 18 Apr 2013, 04:25 AM
Thanks For reply..   but its not working.
I have following code :
void gvTest_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                for (int i = 2; i < ViewData.Tables[0].Columns.Count; i++)
                {
                    TableCell tb = item[ViewData.Tables[0].Columns[i].ColumnName];
                    LinkButton lnk = new LinkButton();
                    lnk.ID = "lnk" + Guid.NewGuid();
                    lnk.Text = item[ViewData.Tables[0].Columns[i].ColumnName].Text;
                    lnk.Text = lnk.Text == " " ? "" : lnk.Text;
                    //tb.Controls.Clear();
                    tb.Controls.Add(lnk);
                }
 
            }
        }
 
void gvTest_ItemCreated(object sender, GridItemEventArgs e)
     {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                for (int i = 2; i < ViewData.Tables[0].Columns.Count; i++)
                {
                    TableCell tb = item[ViewData.Tables[0].Columns[i].ColumnName];
                    LinkButton lnk = new LinkButton();
                    lnk.ID = "lnk" + Guid.NewGuid();
                    lnk.Text = item[ViewData.Tables[0].Columns[i].ColumnName].Text;
                    lnk.Text = lnk.Text == " " ? "" : lnk.Text;
                    //tb.Controls.Clear();
                    tb.Controls.Add(lnk);
                }
            }
        }
What's Problem with this Code?
Tags
Grid
Asked by
Ajay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ajay
Top achievements
Rank 1
Share this question
or