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

Create dynamic link button control in radgrid

1 Answer 255 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
ravi
Top achievements
Rank 1
ravi asked on 24 Feb 2009, 07:29 PM
Hi

    here i am working with radgrid, with each row multiple images. this uploading process.
i have created multiple images for each row. but i want delete option on row. that should  be create  dynamically.

i have code written like this

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            if (!e.Item.OwnerTableView.IsItemInserted)
            {
                LinkButton lbtn = new LinkButton();
                lbtn.ID = "File" + i;
                lbtn.Text = "Delete";
                lbtn.OnClientClick = "return confirm('Are you sure delete this file')";
                lbtn.Click += new System.EventHandler(OnDelete);
                ViewState["UploadID"] = Convert.ToString(dt.Rows[i]["UploadedID"]);
                (e.Item.FindControl("EditplaceHolder") as PlaceHolder).Controls.Add(lbtn);                                      

            }

        }
    }
protected void OnDelete(Object sender, EventArgs e)
        {
            int UpLoadedFileID = Convert.ToInt32(ViewState["UploadID"]);
            objBO.DeleteFileID(UpLoadedFileID);
        }

but onDelete not working when i click on delete which is created dynamically.

please reply ASAP.

thx
ravi


1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Feb 2009, 11:00 AM
Hello Ravi,

An event handler for a control in the grid, should be always added in the grid's ItemCreated event. So try adding the same code in the ItemCreated event of the RadGrid as shown below:
cs:
rotected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            if (!e.Item.OwnerTableView.IsItemInserted) 
            { 
                LinkButton lbtn = new LinkButton(); 
                lbtn.ID = "File" + i; 
                lbtn.Text = "Delete"
                lbtn.OnClientClick = "return confirm('Are you sure delete this file')"
                lbtn.Click += new EventHandler(lbtn_Click); 
                ViewState["UploadID"] = Convert.ToString(dt.Rows[i]["UploadedID"]); 
                (e.Item.FindControl("EditplaceHolder") as PlaceHolder).Controls.Add(lbtn); 
 
            } 
        } 
  
    } 
 
    void lbtn_Click(object sender, EventArgs e) 
    { 
       // code
    } 

Thanks
Princy.
Tags
Upload (Obsolete)
Asked by
ravi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or