PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event.

 
 
Daniel Roth
Guest
Posts: n/a
 
      5th Apr 2005
How to add a Dropdown list to a datagrid at runtime (dynamic) without
using template columns in ASP.NET and still have the ability to us the
datagrid Update event.

1. Dynamiclly add the drowndown in Itemdatabound Event, remove the
textbox and save the UniqueID to the Viewstate

private void DatagridEvents_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.EditItem)
{
CStageCollection oStageCollection =
(CStageCollection)CStageCollection.Create(new
CStageCollection.CreateCriteria());
DataSet oDS = (DataSet)CStageCollection.Fetch(new
CStage.Csp_get_stage_name_id( Convert.ToInt32(
((TextBox)e.Item.Cells[2].Controls[0]).Text ) ));

System.Web.UI.WebControls.DropDownList dDLOriginEvent = new
System.Web.UI.WebControls.DropDownList();

foreach(DataRow dR in oDS.Tables[0].Rows)
{
dDLOriginEvent.Items.Add(dR[1].ToString());
}

dDLOriginEvent.SelectedIndex =
dDLOriginEvent.Items.IndexOf(dDLOriginEvent.Items.FindByValue(
((TextBox)e.Item.Cells[5].Controls[0]).Text) );

e.Item.Cells[5].Controls.RemoveAt(0);

e.Item.Cells[5].Controls.AddAt(0,dDLOriginEvent);

ViewState["dDLOriginEvent"] = e.Item.Cells[5].Controls[0].UniqueID;

}
}


2. In the datagrid Update event use Request.Form.Get with the
Viewstate

private void DatagridEvents_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

CEvents oEvents = new CEvents();

CStageCollection oStageCollection =
(CStageCollection)CStageCollection.Create(new
CStageCollection.CreateCriteria());
DataSet oDS = (DataSet)CStageCollection.Fetch(new
CStage.Csp_get_stage_name_id( Convert.ToInt32(
((TextBox)e.Item.Cells[2].Controls[0]).Text ) ));

foreach(DataRow dR in oDS.Tables[0].Rows)
{
if(oEvents.Origin != null)
{
break;
}

if( dR[1].ToString() ==
Request.Form.Get((string)ViewState["dDLOriginEvent"]) )
{
oEvents.Origin = dR[0].ToString();
}
}

DatagridEvents.EditItemIndex = -1;

try
{
CEvents.Save(oEvents, new CEvents.SaveCriteria());
}
catch
{
Response.Write("TicketsEvents.aspx - Please contact your System
Administrator");
}

BindDataToGridEvents();


}

Daniel Roth
MSCD.NET
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic datagrid dropdown valuechanged repopulate 2nd list editmo =?Utf-8?B?Y2luZHk=?= Microsoft ASP .NET 0 21st Sep 2006 05:40 PM
Datagrid Dropdown columns =?Utf-8?B?cG1hc3RlcnM=?= Microsoft ASP .NET 0 3rd Aug 2005 02:18 PM
Datagrid Template Columns At Runtime =?Utf-8?B?RGF2ZXkgUA==?= Microsoft ASP .NET 0 10th Jun 2005 09:38 AM
add TemplateColumn (dropdown) to DataGrid at runtime Kilic Beg via .NET 247 Microsoft Dot NET 0 27th Apr 2004 11:06 PM
Dynamic Dropdown in DataGrid Niks Microsoft ASP .NET 4 17th Jan 2004 08:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:38 PM.