Team,
In my scenario, I have an autogenerated Radgrid control to bind two Bound columns and remaining columns are Dropdown list. The bound and dropdown list control is binded in Grid. But when I try to get the value from the Dropdown list, I can't able to get the control Id (even i used FindControl).
IN ASPX
----------
<telerik:RadGrid ID="dgPassanger" runat="server" AllowSorting="true" Visible="true"
PageSize="5" AllowPaging="true" AllowFilteringByColumn="true" PagerStyle-AlwaysVisible="true"
OnItemDataBound="Passenger_ItemDataBound" Width="715px">
<MasterTableView CommandItemDisplay="None" AllowFilteringByColumn="false" AutoGenerateColumns="true">
<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="true" />
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
IN ASPX.CS
---------------
protected void PreparePaxGrid(List<Passenger> PaxList)
{
DataTable pivotedList = new DataTable();
try
{
if (Session["PostflightTrip"] != null)
{
TripLog = (PostflightTrip)Session["PostflightTrip"];
// Adding Dynamic Columns
GridBoundColumn boundColumn;
GridTemplateColumn templateColumn;
boundColumn = new GridBoundColumn();
boundColumn.DataField = "PaxCode";
boundColumn.HeaderText = "Pax Code";
dgPassanger.MasterTableView.Columns.Add(boundColumn);
boundColumn = new GridBoundColumn();
boundColumn.DataField = "PaxName";
boundColumn.HeaderText = "Pax Name";
dgPassanger.MasterTableView.Columns.Add(boundColumn);
foreach (var item in TripLog.TripLegs)
{
templateColumn = new GridTemplateColumn();
templateColumn.HeaderText = item.POLegsDescription;
templateColumn.ItemTemplate = new GridTemplate(item.LegID); // Bind Dropdown List
templateColumn.UniqueName = "FlightPurpose";
dgPassanger.MasterTableView.Columns.Add(templateColumn);
}
// Bind List into Grid
dgPassanger.DataSource = PaxLegList;
dgPassanger.DataBind();
}
}
catch (Exception ex) { }
}
private class GridTemplate : ITemplate
{
protected DropDownList ddList;
private int _legId = 0;
public GridTemplate(int legId)
{
_legId = legId;
}
public void InstantiateIn(System.Web.UI.Control container)
{
ddList = new DropDownList();
ddList.ID = "ddlFP" +_legId.ToString();
ddList.DataBinding += new EventHandler(ddList_DataBinding);
container.Controls.Add(ddList);
}
protected void ddList_DataBinding(object sender, EventArgs e)
{
DropDownList dl = (DropDownList)sender;
GridDataItem container = (GridDataItem)dl.NamingContainer;
dl.Items.Add(new ListItem("1","1"));
dl.Items.Add(new ListItem("2", "2"));
//dl.AutoPostBack = true;
//dl.SelectedIndexChanged += new EventHandler(DisplayDDList_IndexChanged);
}
}
For Retrieving Value from Dropdown, I used the below code
foreach (GridDataItem Item in grid.MasterTableView.Items)
{
DropDownList ddlFlightPurpose = (DropDownList)Item["FlightPurpose"].FindControl("ddlFP1");
}
ISSUE: Every time it shows the NULL value.
Please resolve as soon as possible.
In my scenario, I have an autogenerated Radgrid control to bind two Bound columns and remaining columns are Dropdown list. The bound and dropdown list control is binded in Grid. But when I try to get the value from the Dropdown list, I can't able to get the control Id (even i used FindControl).
IN ASPX
----------
<telerik:RadGrid ID="dgPassanger" runat="server" AllowSorting="true" Visible="true"
PageSize="5" AllowPaging="true" AllowFilteringByColumn="true" PagerStyle-AlwaysVisible="true"
OnItemDataBound="Passenger_ItemDataBound" Width="715px">
<MasterTableView CommandItemDisplay="None" AllowFilteringByColumn="false" AutoGenerateColumns="true">
<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="true" />
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
IN ASPX.CS
---------------
protected void PreparePaxGrid(List<Passenger> PaxList)
{
DataTable pivotedList = new DataTable();
try
{
if (Session["PostflightTrip"] != null)
{
TripLog = (PostflightTrip)Session["PostflightTrip"];
// Adding Dynamic Columns
GridBoundColumn boundColumn;
GridTemplateColumn templateColumn;
boundColumn = new GridBoundColumn();
boundColumn.DataField = "PaxCode";
boundColumn.HeaderText = "Pax Code";
dgPassanger.MasterTableView.Columns.Add(boundColumn);
boundColumn = new GridBoundColumn();
boundColumn.DataField = "PaxName";
boundColumn.HeaderText = "Pax Name";
dgPassanger.MasterTableView.Columns.Add(boundColumn);
foreach (var item in TripLog.TripLegs)
{
templateColumn = new GridTemplateColumn();
templateColumn.HeaderText = item.POLegsDescription;
templateColumn.ItemTemplate = new GridTemplate(item.LegID); // Bind Dropdown List
templateColumn.UniqueName = "FlightPurpose";
dgPassanger.MasterTableView.Columns.Add(templateColumn);
}
// Bind List into Grid
dgPassanger.DataSource = PaxLegList;
dgPassanger.DataBind();
}
}
catch (Exception ex) { }
}
private class GridTemplate : ITemplate
{
protected DropDownList ddList;
private int _legId = 0;
public GridTemplate(int legId)
{
_legId = legId;
}
public void InstantiateIn(System.Web.UI.Control container)
{
ddList = new DropDownList();
ddList.ID = "ddlFP" +_legId.ToString();
ddList.DataBinding += new EventHandler(ddList_DataBinding);
container.Controls.Add(ddList);
}
protected void ddList_DataBinding(object sender, EventArgs e)
{
DropDownList dl = (DropDownList)sender;
GridDataItem container = (GridDataItem)dl.NamingContainer;
dl.Items.Add(new ListItem("1","1"));
dl.Items.Add(new ListItem("2", "2"));
//dl.AutoPostBack = true;
//dl.SelectedIndexChanged += new EventHandler(DisplayDDList_IndexChanged);
}
}
For Retrieving Value from Dropdown, I used the below code
foreach (GridDataItem Item in grid.MasterTableView.Items)
{
DropDownList ddlFlightPurpose = (DropDownList)Item["FlightPurpose"].FindControl("ddlFP1");
}
ISSUE: Every time it shows the NULL value.
Please resolve as soon as possible.