Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Daniel Roth #1
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.
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
Daniel Roth Guest
-
Changing Datagrid columns at runtime
Dear all, I'm writing an ASP.NET application, which allows flexible editing of tables stored in an oracle database. Therefore, it is necessary to... -
add TemplateColumn(dropdown) to DataGrid at runtime
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime.... -
Dynamic datagrid template Columns Need Help.
I am having problems trying to create these template columns dynamically. '<Columns> ' <asp:TemplateColumn> ' <ItemTemplate> ' <asp:LinkButton... -
Dropdown event in datagrid
Hi, I have a dropdownlist in a datagrid and want to respond to the SelectedItemChanged event. I can't seem to find the dropdownlist in the class... -
Adding Columns at runtime in datagrid control
have a datgrid control that has 3 columns defined at design time. Remaining columns are coming from a query and not known until runtime. I have...



Reply With Quote

