473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

dynamic datagrid dropdown valuechanged repopulate 2nd list editmo

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[i][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\webform 1.aspx.cs:line 804 at
System.Web.UI.WebControls.DataGrid.OnItemDataBound (DataGridItemEventArgs e)
at System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource) at
System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean
useDataSource) at
System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(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\webform 1.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 changed in the database. Please help me. Thank you cindy
Sep 21 '06 #1
0 2885

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sara | last post by:
Hi- I have created a dropdown list in my VB.net application, with data from a database table - that works fine. I then added a record to a table through a form that has this drop down list -...
4
by: TaeHo Yoo | last post by:
I have two dropdown list(ie State and Region) that are populated with data from database. I want to repopulate the second dropdown list(Region) according to what state user has selected without...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
2
by: JIM.H. | last post by:
Hello, I have a dropdown list, updated through a dataset. After bind, I use this to add extra item to my dropdown list. myDropDownList.Items.Add(“Item1”), I can remove that by using...
1
by: Elliot Rodriguez | last post by:
I have a dropdown list that defines the number of textboxes that appear within a particular panel. The boxes are created when the dropdownlist's SelectedIndexChanged event fires on postback. ...
0
by: satees | last post by:
Hi, I have displayed firstname, lastname and city fields in the datagrid. In these, first two are bound columns and the city is template column which has dropdown list control. When i click...
0
TonFrere
by: TonFrere | last post by:
Hello, I'm building a windows form application in Visual C# using VS 2005. On my form I need to populate a combobox with Invoices# linked to the current reccord's Order# value. This means that: -...
2
by: kennywu | last post by:
I am using a databound dropdown list bound to a sql datasource in C# .NET environment. When the user opts to delete an entry from the dropdown list, the dropdown list does not reflect the change,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.