C
cindy
I am sorry I can't tell if the first message posted, sorry if this is a
repost truly.
I have a dynamic datagrid. I have custom classes for the controls
public class CreateEditItemTemplateDDL : ITemplate {
DataTable dtBind;
string strddlName;
string strSelectedID;
string strDataValueField;
string strDataTextField;
public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
DataTextField,string SelectedValueField,DataTable DDLSource){
dtBind=DDLSource;
strDataValueField=DataValueField;
strDataTextField=DataTextField;
strSelectedID=SelectedValueField;
this.strddlName=DDLName;}
public void InstantiateIn(Control objContainer){
DropDownList ddl = new DropDownList();
ddl.DataBinding+=new EventHandler(ddl_DataBinding);
objContainer.Controls.Add(ddl);}
private void ddl_DataBinding(object sender, EventArgs e){
DropDownList ddl= (DropDownList)sender;
ddl.ID=strddlName;
ddl.DataSource=dtBind;
ddl.DataValueField=strDataValueField;
ddl.DataTextField=strDataTextField;
for (int i=0;i<dtBind.Rows.Count;i++){
if(strSelectedID == dtBind.Rows[strDataValueField].ToString())
{
ddl.SelectedIndex=i; }
}}}
I do a creategrid and display the grid from dataset after load
I can get the selected values from hidden fields.
MY Problem
How can the user select a new value in the first drop down list and change
the
range of possible values in the second drop down list, select the new values
and then update the row back to the database. (I know how to do the update
it
is the display of a new range of values in the second list have the first
list
has an index changed event.) Example the first list from database has 2
values
fruit and vegetable, vegetable is selected for the database row in edit mode
and in the second list where tomato was selected (choices might be lettuce or
tomato.) the choice violates database integrity data needs to have been
repopulated to show the fruit range of choices. User selects value fruit
first
list, I need the second list to repopulate with range of fruits example
orange
and grape, new row at top inserted value is 0 says pick a fruit. I started
with creating an ascx control which is a dropdown list. I can get this
control
to drop on an aspx form with a label, choose a new value and based on event
handler for index changed in the ascx return the new value based on the index
selected to the form label showing the value for the selected list array. I
next put this ascx in the datagrid with
ITemplate temp= Page.LoadTemplate("Controls/StoreSelector.ascx");
tcl5.EditItemTemplate = temp;
//the control id is storeList
I had to first change to ascx code to get this to work, in the databind on
page
load in the ascx I can not do a check for (!(Page.IsPostBack)) because the
list
is displayed only when the row is clicked for edit so if I did that the list
does not populate with any values.
Next how do I get the dropdown list selected value to be the value from the
datagrid underlying datatable for the row. What am I doing inside the ascx
(what public exposure) that I can access the property in the event
itemdatabound of the datagrid to set the selected value? I always get the
first item in the dropdownlist.
I tried putting in the ascx code behind
public string SelectedValue{
get{return storeList.SelectedValue;}
set{storeList.SelectedValue = value;}
}
In the aspx code behind I try to pass a value from datagrid datatable for the
row
private void dgRt2_ItemDataBound(object sender, DataGridItemEventArgs e){
DataGrid dg = (DataGrid)sender;
int cnt = e.Item.ItemIndex + (dg.PageSize * dg.CurrentPageIndex);
DataTable dtBound = (DataTable)dg.DataSource;
if(e.Item.ItemType==ListItemType.EditItem) {
string strZone = dtBound.Rows[cnt]["zonelu"].ToString();
SISWebAdmin.Controls.StoreSelector ddlz =
(SISWebAdmin.Controls.StoreSelector)e.Item.Cells[0].FindControl("storeList");
ddlz.SelectedValue = strZone;}
When I debug I pass the line where I do a cast of the control to the ascx and
do a find control in the datagrid
I have the correct string in the strZone variable from the datatable that I
need to set to but I error on the line ddlz .SelectedValue = strZone
I get the follow error message and stack trace
e1 at SISWebAdmin.WebForm1.dgRt2_ItemDataBound(Object sender,
DataGridItemEventArgs e) in c:\program files\common files\microsoft
shared\web
server extensions\60\template\layouts\siswebadmin\webform1.aspx.cs:line 804
at
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e)
at
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource) at
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource) at
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) at
System.Web.UI.WebControls.BaseDataList.DataBind() at
SISWebAdmin.WebForm1.fillgrid(String sFullname, String strZone, String
strArea,
String strTitle) in c:\program files\common files\microsoft shared\web server
extensions\60\template\layouts\siswebadmin\webform1.aspx.cs:line 368Object
reference not set to an instance of an object.SISWebAdmin
For weeks I could not get into news groups, account issues I don't know what
and have posted everywhere, no replies. If there is a better way tell me, I
have 3 dropdowns in dynamic grid that basically depend on each other for
their
range of values. The user in edit mode would theorectically changed the
first
range and need new value selection for second then third before the row can
be
repost truly.
I have a dynamic datagrid. I have custom classes for the controls
public class CreateEditItemTemplateDDL : ITemplate {
DataTable dtBind;
string strddlName;
string strSelectedID;
string strDataValueField;
string strDataTextField;
public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
DataTextField,string SelectedValueField,DataTable DDLSource){
dtBind=DDLSource;
strDataValueField=DataValueField;
strDataTextField=DataTextField;
strSelectedID=SelectedValueField;
this.strddlName=DDLName;}
public void InstantiateIn(Control objContainer){
DropDownList ddl = new DropDownList();
ddl.DataBinding+=new EventHandler(ddl_DataBinding);
objContainer.Controls.Add(ddl);}
private void ddl_DataBinding(object sender, EventArgs e){
DropDownList ddl= (DropDownList)sender;
ddl.ID=strddlName;
ddl.DataSource=dtBind;
ddl.DataValueField=strDataValueField;
ddl.DataTextField=strDataTextField;
for (int i=0;i<dtBind.Rows.Count;i++){
if(strSelectedID == dtBind.Rows[strDataValueField].ToString())
{
ddl.SelectedIndex=i; }
}}}
I do a creategrid and display the grid from dataset after load
I can get the selected values from hidden fields.
MY Problem
How can the user select a new value in the first drop down list and change
the
range of possible values in the second drop down list, select the new values
and then update the row back to the database. (I know how to do the update
it
is the display of a new range of values in the second list have the first
list
has an index changed event.) Example the first list from database has 2
values
fruit and vegetable, vegetable is selected for the database row in edit mode
and in the second list where tomato was selected (choices might be lettuce or
tomato.) the choice violates database integrity data needs to have been
repopulated to show the fruit range of choices. User selects value fruit
first
list, I need the second list to repopulate with range of fruits example
orange
and grape, new row at top inserted value is 0 says pick a fruit. I started
with creating an ascx control which is a dropdown list. I can get this
control
to drop on an aspx form with a label, choose a new value and based on event
handler for index changed in the ascx return the new value based on the index
selected to the form label showing the value for the selected list array. I
next put this ascx in the datagrid with
ITemplate temp= Page.LoadTemplate("Controls/StoreSelector.ascx");
tcl5.EditItemTemplate = temp;
//the control id is storeList
I had to first change to ascx code to get this to work, in the databind on
page
load in the ascx I can not do a check for (!(Page.IsPostBack)) because the
list
is displayed only when the row is clicked for edit so if I did that the list
does not populate with any values.
Next how do I get the dropdown list selected value to be the value from the
datagrid underlying datatable for the row. What am I doing inside the ascx
(what public exposure) that I can access the property in the event
itemdatabound of the datagrid to set the selected value? I always get the
first item in the dropdownlist.
I tried putting in the ascx code behind
public string SelectedValue{
get{return storeList.SelectedValue;}
set{storeList.SelectedValue = value;}
}
In the aspx code behind I try to pass a value from datagrid datatable for the
row
private void dgRt2_ItemDataBound(object sender, DataGridItemEventArgs e){
DataGrid dg = (DataGrid)sender;
int cnt = e.Item.ItemIndex + (dg.PageSize * dg.CurrentPageIndex);
DataTable dtBound = (DataTable)dg.DataSource;
if(e.Item.ItemType==ListItemType.EditItem) {
string strZone = dtBound.Rows[cnt]["zonelu"].ToString();
SISWebAdmin.Controls.StoreSelector ddlz =
(SISWebAdmin.Controls.StoreSelector)e.Item.Cells[0].FindControl("storeList");
ddlz.SelectedValue = strZone;}
When I debug I pass the line where I do a cast of the control to the ascx and
do a find control in the datagrid
I have the correct string in the strZone variable from the datatable that I
need to set to but I error on the line ddlz .SelectedValue = strZone
I get the follow error message and stack trace
e1 at SISWebAdmin.WebForm1.dgRt2_ItemDataBound(Object sender,
DataGridItemEventArgs e) in c:\program files\common files\microsoft
shared\web
server extensions\60\template\layouts\siswebadmin\webform1.aspx.cs:line 804
at
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e)
at
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource) at
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource) at
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) at
System.Web.UI.WebControls.BaseDataList.DataBind() at
SISWebAdmin.WebForm1.fillgrid(String sFullname, String strZone, String
strArea,
String strTitle) in c:\program files\common files\microsoft shared\web server
extensions\60\template\layouts\siswebadmin\webform1.aspx.cs:line 368Object
reference not set to an instance of an object.SISWebAdmin
For weeks I could not get into news groups, account issues I don't know what
and have posted everywhere, no replies. If there is a better way tell me, I
have 3 dropdowns in dynamic grid that basically depend on each other for
their
range of values. The user in edit mode would theorectically changed the
first
range and need new value selection for second then third before the row can
be