473,225 Members | 1,313 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,225 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 2871

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,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.