Solved

dynamically created control added to datagrid cell event will not fire

Posted on 2007-03-18
4
452 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

707 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