473,740 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic datagrid dropdown valuechanged repopulate 2nd list editmo

I have a dynamic datagrid. I have custom classes for the controls

public class CreateEditItemT emplateDDL : ITemplate {
DataTable dtBind;
string strddlName;
string strSelectedID;
string strDataValueFie ld;
string strDataTextFiel d;

public CreateEditItemT emplateDDL(stri ng DDLName,string DataValueField, string
DataTextField,s tring SelectedValueFi eld,DataTable DDLSource){
dtBind=DDLSourc e;
strDataValueFie ld=DataValueFie ld;
strDataTextFiel d=DataTextField ;
strSelectedID=S electedValueFie ld;
this.strddlName =DDLName;}
public void InstantiateIn(C ontrol objContainer){
DropDownList ddl = new DropDownList();
ddl.DataBinding +=new EventHandler(dd l_DataBinding);
objContainer.Co ntrols.Add(ddl) ;}

private void ddl_DataBinding (object sender, EventArgs e){
DropDownList ddl= (DropDownList)s ender;
ddl.ID=strddlNa me;
ddl.DataSource= dtBind;
ddl.DataValueFi eld=strDataValu eField;
ddl.DataTextFie ld=strDataTextF ield;
for (int i=0;i<dtBind.Ro ws.Count;i++){
if(strSelectedI D == dtBind.Rows[i][strDataValueFie ld].ToString()) {
ddl.SelectedInd ex=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.LoadTempla te("Controls/StoreSelector.a scx");
tcl5.EditItemTe mplate = 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.IsPostB ack)) 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.Selec tedValue;}
set{storeList.S electedValue = value;}

In the aspx code behind I try to pass a value from datagrid datatable for
the row

private void dgRt2_ItemDataB ound(object sender, DataGridItemEve ntArgs e){
DataGrid dg = (DataGrid)sende r;
int cnt = e.Item.ItemInde x + (dg.PageSize * dg.CurrentPageI ndex);
DataTable dtBound = (DataTable)dg.D ataSource;

if(e.Item.ItemT ype==ListItemTy pe.EditItem) {
string strZone = dtBound.Rows[cnt]["zonelu"].ToString();
SISWebAdmin.Con trols.StoreSele ctor ddlz =
(SISWebAdmin.Co ntrols.StoreSel ector)e.Item.Ce lls[0].FindControl("s toreList");
ddlz.SelectedVa lue = 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.Web Form1.dgRt2_Ite mDataBound(Obje ct sender,
DataGridItemEve ntArgs e) in c:\program files\common files\microsoft
shared\web server
extensions\60\t emplate\layouts \siswebadmin\we bform1.aspx.cs: line 804 at
System.Web.UI.W ebControls.Data Grid.OnItemData Bound(DataGridI temEventArgs e)
at System.Web.UI.W ebControls.Data Grid.CreateItem (Int32 itemIndex, Int32
dataSourceIndex , ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollect ion rows, PagedDataSource
pagedDataSource ) at
System.Web.UI.W ebControls.Data Grid.CreateCont rolHierarchy(Bo olean
useDataSource) at
System.Web.UI.W ebControls.Base DataList.OnData Binding(EventAr gs e) at
System.Web.UI.W ebControls.Base DataList.DataBi nd() at
SISWebAdmin.Web Form1.fillgrid( String sFullname, String strZone, String
strArea, String strTitle) in c:\program files\common files\microsoft
shared\web server
extensions\60\t emplate\layouts \siswebadmin\we bform1.aspx.cs: line 368Object
reference not set to an instance of an object.SISWebAd min
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 2909

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

Similar topics

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 - that worked fine too. The problem is now selecting and displaying this value. All the other fields are displayed fine, but the drop down list comes out blank - any idea as to what I am doing wrong? Thanks
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 posting back to the server. How do I implement this? Thanks a lot in advance.
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 dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
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 Dropdown item selection is applied to the next dropdown list. Is there any way to fix this problem?
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 myDropDownList.Items.Remove(“Item1”), If I try to remove something coming from dataset, it seems I could not remove it. Is there any way to do that, or is there any why to write a SQL string and update dropdown list. Thanks, Jim.
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. Also in the form is a datagrid that has some custom validation performed on values within its rows. The validation is server side but not tied into any ValidatorControls. When the form is submitted, if the datagrid contains values that are invalid...
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 "Add new row" button, i need to add one dynamic row which has two textbox and one dropdown fields within the datagrid. After entering the value, it will br displayed in the datagrid. Plz help me how to do this.. Thanks in advance.
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: - The combobox should repopulate if the user changes the value of Order#. - The combobox should repopulate if the user moves through records (using the binding navigator. My problem is that whenever I repopulate the combobox, it's value is reset to...
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, even on postback. i.e. ddlColors = red, yellow, blue, green; user selects to delete red; ddlColors = red, yellow, blue, green. Red is still displayed. I am able to clear the dropdown list with ddlColors.ClearSelection(); But I don't know how...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.