Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

dynamically created control added to datagrid cell event will not fire

Posted on 2007-03-18
4
446 Views
Last Modified: 2013-11-07
I have a datagrid that shows a dropdownlist in the row cell when I click the datagrid edit link. When the selected index change event fired for the dropdownlist I am dynamically creating controls (linkButton) at runtime and adding it to the cell and hiding the dropdownlist.
PROBLEM:
When the linkButton is clicked I cannot get and event to fire. The DataGrid ItemCommand event does not fire and the event I created when I dynamically added the control to the cell will not fire. Does anyone know how to fire an event for a control dynamically created and added to a datagrid cell?
0
Comment
Question by:jtwoods4
  • 2
4 Comments
 
LVL 13

Expert Comment

by:KarinLoos
ID: 18742880
Dynamic controls need to be created in the rowcreated event of the grid. Maybe it would be easier to have the linkbutton in your edititemtemplate but with visible=false, and merely show/hide appropriately.
0
 

Author Comment

by:jtwoods4
ID: 18743442
Excellent idea. I did not think of looking at the problem from this angle. I created the link button in the EditItemTemplate and set the visibility to false. How do I access the LinkButton in my code behind so I can set the visibility to true when the user selects an item from the DropDowList? I think this is why I avoided this mehtod before. Here is my code when the user selects an item from the drop down list.

public void SelectedIndexChanged(object sender, System.EventArgs e)
{
           DropDownList DropDownList1 = (DropDownList)sender;
           if (DropDownList1.SelectedValue == "-1")
           {
      DropDownList1.Visible = false;
                     //Need to show the link button here.....
           }
}
0
 
LVL 13

Accepted Solution

by:
KarinLoos earned 500 total points
ID: 18743922
Well thats quite simple really:

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList list = (DropDownList)sender;
           if (list.SelectedValue == "-1")
           {
                // pick up the parent of the dropdownlist which is a datagrid item
                 TableCell cell = list.Parent as TableCell;
                 DataGridItem item = cell.Parent as DataGridItem;
                // now get the itemindex of the datagrid
                 int index = item.ItemIndex;
               // once you have this you can use this to find the linkbutton in the datagrid
               //  and then set its visibility of the linkbutton and the dropdownlist itself.
                  }
       )
   
}

0
 
LVL 1

Expert Comment

by:AhmedMozaly
ID: 18746547
if you are using asp.net
replace your datagrid with gridview
then do the same things you want in it , it will raise the SelectedIndexChanged
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question