Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dynamically created control added to datagrid cell event will not fire

Posted on 2007-03-18
4
Medium Priority
?
459 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

618 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