Forms Data Controls :: Getting Values From A Dynamic Dropdownlist?

Jan 25, 2011

i have created a dynamic dropdownlist. i need to get the selected values from the list and store it in my sql database. i am new to asp.

View 5 Replies

Similar Messages:

Forms Data Controls :: Dynamic Gridview With Dropdownlist / Dynamically Set The List Values Based On Parameters (of The Row They Are On)

May 28, 2010

I'm new to web dev and c# so please bare with me. I am trying to create a dynamic gridview in a web form for users to to answer questions with (code below).

The dificulty im having is that i am nesting a dropdwonlist in the gridview and want to be able to dynamically set the list values based on parameters (of the row they are on). These values are in the main dataset for the gridview as each row represents a questionid and question text and then a ddl for the criteria...

I just don't know how to set the values for the dropdown all the code so far is below... just need to be able to populate the dropdowns with the relevant values.

I have created a stored proc to return the different criteria based on the questionid and questionGroupid which is the dataset that populates the other fields in the gridview: dbo.usp_QuestionCriteria @QuestionGroupId, @QuestionId

I have added this as a tableadapter called criteriaTableAdapter in a xsd file as well using the wizard... not sure if this is the right option though or just use the same method as i have for the other stored procedure as in the code below:


]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
SqlCommand com = new SqlCommand("usp_QuestionGroupDS", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataSet ds = new DataSet();
for (int i = 0; i < ds.Tables.Count; i++)
if (ds.Tables[i].Rows.Count > 0)
GridView gvDynamicQuestion = new GridView();
gvDynamicQuestion.Width = Unit.Pixel(700);
gvDynamicQuestion.BorderWidth = Unit.Pixel(0);
gvDynamicQuestion.Caption = "<div id="nifty" class="QuestionGroup"> <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>" + ds.Tables[i].Rows[0]["Category"].ToString() + " Questions<b class="rbottom"><b
class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div>";
gvDynamicQuestion.AutoGenerateColumns = false;
gvDynamicQuestion.ShowFooter = true;
TemplateField tf = null;
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.DataRow);
tf.FooterTemplate = new DynamicGridViewTextTemplate(DataControlRowType.Footer, ds.Tables[i].Rows.Count);
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.DataRow);
tf = new TemplateField();
tf.HeaderText = "Criteria";
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Criteria", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewDDLTemplate();
////tf = new TemplateField();
////tf.HeaderText = "Criteria";
////tf.ItemTemplate = new DynamicGridViewDDLTemplate();
gvDynamicQuestion.DataSource = ds.Tables[i];
protected void DynamicGrid_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.Footer)
public class DynamicGridViewTextTemplate : ITemplate
string _ColName;
DataControlRowType _rowType;
int _Count;
public DynamicGridViewTextTemplate(string ColName, DataControlRowType RowType)
_ColName = ColName;
_rowType = RowType;
public DynamicGridViewTextTemplate(DataControlRowType RowType, int QuestionCount)
_rowType = RowType;
_Count = QuestionCount;
public void InstantiateIn(System.Web.UI.Control container)
switch (_rowType)
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + _ColName + "</b>";
case DataControlRowType.DataRow:
Label lbl = new Label();
lbl.DataBinding += new EventHandler(this.lbl_DataBind);
case DataControlRowType.Footer:
Literal flc = new Literal();
flc.Text = "<b>Total No of Questions:" + _Count + "</b>";
private void lbl_DataBind(Object sender, EventArgs e)
Label lbl = (Label)sender;
GridViewRow row = (GridViewRow)lbl.NamingContainer;
lbl.Text =DataBinder.Eval(row.DataItem, _ColName).ToString();
public class DynamicGridViewDDLTemplate : ITemplate
// Implementation of ITemplate
public void InstantiateIn(System.Web.UI.Control container)
// Create a DDL
DropDownList ddl = new DropDownList();
//Attach method to delegate
ddl.DataBinding += new System.EventHandler(this.ddl_DataBind);
//Method that responds to the DataBinding event
private void ddl_DataBind(object sender, System.EventArgs e)
//DropDownList ddl = (DropDownList)sender;
//DataGridItem container = (DataGridItem)ddl.NamingContainer;
//ddl.Data.Checked = [Data binding expression];


View 7 Replies

Data Controls :: Sort GridView Using Dynamic Field Values From DropDownList

Mar 14, 2013

I have a gridview which is having coloumns Company name, Industry type, country, employees, revenue. i want to add dropdown at the top of each coloumn so that if user select industry as agriculture, all agriculture industry rows may be sorted, and same for other dropdown also.. i it may be possible,

View 1 Replies

Data Controls :: Using DropDownList In Gridview And Bind Values In DropDownList

Oct 9, 2012

UsingĀ  dropdown in gridview and bind the values in dropdown then based on dropdown display the value in another column.

View 1 Replies

Forms Data Controls :: DropDownList With Dynamic Datasource In EditItemTemplate In Gridview?

Mar 2, 2011

I have two embedded dropdown lists in Gridview control. One gives you business channel options and the other represents products depending on the business channel selected.I am trying to use different data sources for product dropdown list depeding on what the user selected from the business channel drop down list. How could I do this. Here is my current code:


View 2 Replies

Forms Data Controls :: Unable To Get Dynamic Generated Dropdownlist Item

Sep 22, 2010

i'm using 3.5 and what im trying to do is create the dropdownlist item dynamically base on value in each datarow, then user select from dropdownlist and click button to postback, when postback system should be able to know what value has been selected by user. the problem with following code is during postback, event of "OnItem_Created" get fired and e.Item.DataItem return null, therefore the dropdownlist will not get populated with the items and that caused the dropdownlist unable to return value selected by user. am i missing anything? is "OnItemCreated" the best place to dynamic create the dropdownlist item?


View 2 Replies

Forms Data Controls :: ListView Dropdownlist Dynamic Select Command On Insert?

Jul 6, 2010

I would like to know if I can do the following: when I am in insert mode, can I dynamically change the select command of and then display that result in the second dropdownlist based on what was selected in the first dropdownlist.

I would like to include the minimum code to demonstrate what I am trying to do.



View 4 Replies

Forms Data Controls :: Get Values From Dynamic Fields In A For Loop - Autopostback And Comparing

Jan 31, 2011

I am dealing with dynamic fields in a for loop and now I need to retrieve the values that are being typed in the dynamic fields, any idea how can I do that? 2)also when I click the submit button, upon postback, the dynamic fields have gone missing, have been trying to slove that, but i did not, anyone knows how to deal with this? kinda urgent :x

3) and How do you compare the 2 dynamic fields? For eg: Im comparing the tbSch[i] to tbSch[i], so that the dates cannot be the same, am using a compare validator, but it throws me error that im comparing the same fields :) even though i change to ("tbSch" + i) for both, sorry Will provide my code snippet as follow :D tbNum is a textbox where user enter numbers and click generate

protected void btnGen_Click(object sender, EventArgs e)
for (int i = 0; i < Convert.ToInt32(tbNum.Text); i++)
// label and textbox needed
Label lblSch = new Label();
TextBox tbSch = new TextBox();
Label lblWsGrp = new Label();
DropDownList ddlWsGrp = new DropDownList();
CompareValidator cvSame = new CompareValidator();
cvSame.ID = "cvSame" + i;
cvSame.ErrorMessage = "Date cannot be the same";
cvSame.Operator = ValidationCompareOperator.NotEqual;
cvSame.Type = ValidationDataType.Date;
cvSame.Display = ValidatorDisplay.Dynamic;
cvSame.EnableViewState = true;
cvSame.ControlToValidate = (tbSch.ID);<<<<< what should be the value in here?
cvSame.ControlToCompare = (tbSch.ID);<<<<<<<<<< and here?
//schdule date
lblSch.ID = "lblSch" + i;
lblSch.Text = "Session Date : ";
lblSch.EnableViewState = true;
tbSch.ID = "tbSch" + i;
tbSch.Width = 210;
tbSch.Height = 27;
tbSch.EnableViewState = true;
//workshop grp
lblWsGrp.ID = "lblwsgrp" + i;
lblWsGrp.Text = "Workshop Group : ";
lblWsGrp.EnableViewState = true;
ddlWsGrp.ID = "ddlWsGrp" + i;
ddlWsGrp.Height = 27;
ddlWsGrp.Width = 210;
ddlWsGrp.EnableViewState = true;
//table to store data
TableRow trow = new TableRow();
TableRow trow2 = new TableRow();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();
TableCell tc4 = new TableCell();
TableCell tc5 = new TableCell();
TableCell tc6 = new TableCell();
TableCell tc7 = new TableCell();
TableCell tc8 = new TableCell();
TableCelltc9 = new TableCell();

View 11 Replies

Forms Data Controls :: On Dynamic Control The DropDownList SelectedIndexChanged Event Fires Several Times?

Aug 4, 2010

I ask for a date, on OnTextChanged event i bind data with a SqlDataSource to a dropdownlist and also bind data to a repeater passing the dropdownlist SelectedIndex (i use SqlDataSource too and ControlParameter to link the dropdownlist and the repeater) On my repeater during the ItemDataBound event i create dynamic dropdownlist controls, my code is :



On the Page_load event of my page i bind the data & recreate the control :


Everything works fine, datas are bound and SelectedIndexes are restore on every postback.

The probem occurs when user change different dropdownlists, if he choose to change the 1st dropdownlist the event is fire (normal), after if he modifies another dropdownlist the event is fire twice, if he modifies a 3rd time the event is fire 3 time etc...

View 18 Replies

Forms Data Controls :: Dropdownlist Values With Quotes?

Oct 29, 2010

I have a dropdownlist which gets the data from the oracle database, the values that contains quotes example "Apple's" or "Website's" or not getting seelcted from the list except these values remaining values have no issues.

View 3 Replies

Forms Data Controls :: DropDownList Append With Old Values

Jan 17, 2011

my c# web application populating dropdowns with datas at run time... i.e my web form contains 3 dropdowns and one gridview.. dropdown1 populate with 'pgmtitle' which is fetch from database,when user select one item-pgmtitle from dropdown1,participants(BadgeNo,Name)
of that pgm will be populated in gridview. when user click on the participant badgeno,dropdownlist3 will poputated with recieving officers name.. wen user select one of the recieving officer from dropdown3,his designation is dispalyed in a textbox,and dropdon2
will populated with feedback sentdate... this is my requirement... and my pblm is, when i choose another pgmtilte(say pgmtilte2) from dropdownlist1,previous value associated with(pgmtilte1) appended with dropdown2 and dropdown3.. here is my HTML code:-


View 9 Replies

Forms Data Controls :: Display Dynamic Gridview Headertext Values From Resource Files?

Jun 20, 2010

how to load Gridview HeaderText values from resource (.resx) files.I want to display headertext values for Gridview based on two different application dynamically.

View 6 Replies

Forms Data Controls :: DropDownList Is Showing Double Values?

Jun 10, 2010

I have a DropDownList on my webpage using an Access Database to fill it. However in my database record there a multible values with the same name.

My situation now:


What I want:


I only want to show every value (name) just once!

View 4 Replies

Forms Data Controls :: Change The Values In Dropdownlist In Gridview?

Aug 4, 2010

I got a gridview -CompGrid, having 3 columns - Dept, Employees, Status.

The 'Status' tab need to be edited. So that I put a Dropdownlist as an Itemtemplate and connected the 'DataValueField' as 'Status'.

Now I can edit each row by row only. Some times it needs to update all the employees status in one department.

So that I placed 2 more dropdownlists in outside of gridview.

1. Department List, 2. Status List.

My requirement is this, When I select one department and corresponding status, it should update all the records of that department in the grid.

View 3 Replies

Forms Data Controls :: Use DropDownList To Query Db To Include All Values With Exceptions

Jan 21, 2011

Trying to use a dropdownlist to query a database so that it will return all values except 1 (or more in future versions).

For example, assume you had a simple table name "MYFRIENDS" which has two fields named "GROUP" and "NAME" with the following records:


What I want to do is create a DropDownList that has only 2 list items related to the "GROUP" field. The first list item should return records from the database related to Group A only. Then, the second list item should return all other records EXCLUDING those belonging to Group A.

The drop down list should look something like this (I've put a question mark where I don't know what to do):


After the selection is chosen in the above drop down list, it should query the database and return the desired result. I'm using an AccessDataSource with select parameters. Here's a sample of what that looks like:


Things I've tried that didn't work:

I tried using "Not A" as the the 2nd list item's value. I was thinking p1 would be replaced with the value "Not A" and the query would read "WHERE GROUP LIKE Not A". But, the query syntax "Like Not" is technically wrong. I tried changing the Where Clause to "WHERE GROUP p1" and then replaced the list item's value to "LIKE A" and the second to "NOT LIKE A". Again, I was thinking p1 would be replaced to read "WHERE GROUP LIKE A" and "WHERE GROUP NOT LIKE A". I also tried changing the "SelectCommand" itself so that after the dropdownlist changed, it would first change the selectcommand first and then run the query.

Why the first 2 items didn't work became somewhat obvious to me after thinking about it for a little while. However, I would think the 3rd one would/should work... as long as you have the sequence of events correct which up to this point I haven't been able to figure out.

View 3 Replies

Forms Data Controls :: Dropdownlist Won't Display Values In Gridview With Use Of Parameter

Jan 31, 2010

My database has 4 colums;


Singles and suppers are money fields for the price of same item. A bit like the price of a Small, Medium or Large item. What I would like to do is display the 'Singles' price and 'Suppers' price in seperate listitems so the user can choose 1 of them.

Traditional Name__________Size

Price of Single is: £1.50
Price of Supper is: £2.50

My page loads up with the correct items in TraditionalName colum but the DropDownList is completely empty. I'm aware I don't have anything in for DataValueField and DataTextField but I have tried putting things in these attributes, like Suppers and Singles, but nothing works, so I have taken them out below.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TraditionalID" DataSourceID="SqlDataSource1">
<asp:BoundField DataField="TraditionalID" HeaderText="TraditionalID" InsertVisible="False" ReadOnly="True" SortExpression="TraditionalID" Visible="False" />
<asp:BoundField DataField="TraditionalName" HeaderText="Meal" SortExpression="TraditionalName" />
<asp:templateField HeaderText="Size">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2">
<asp:HiddenField ID="RowTraditionalName" runat="server" Visible="false" Value='<%# Eval("TraditionalName") %>' />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:The CodfatherConnectionString %>"
SelectCommand="SELECT Suppers AS Suppers, Singles AS Singles FROM [Traditional] WHERE TraditionalName = @TraditionalName">
ControlParameter Name="TraditionalName" Type="String" ControlID="RowTraditionalName" PropertyName="Value" />

View 1 Replies

Forms Data Controls :: Update Form Won't Post DropDownList Values

Apr 19, 2010

See what happens when you answer my questions! I come back! No good deed goes unpunished. I've built an Update form where my visitor can update data in dbase. I have a formview with several dropdown lists; none of which will update the table (all the textboxes, checkboxes and even Ajax enabled calendar work just fine). In the form below, visitor selects a CareerCluster from the ddl. Upon postback, the next ddl (pathwayListBox) populates with related data using the CareerCluster.selectedvalue in a query. At the same time, tsaOrgsDropDownList is also populated based upon the first ddl (CareerCluster).

When user selects from the tsaOrgsDropDownList the final ddl (tsaDropDownList) is populated. All this various selecting/populating works just fine on the form. The problem is: Nothing is updated to the table upon clicking the Update button. All other form fields do post as their supposed to except, I have other ddls on the page that are not related to the above series and they won't post either. My thought is that somehow, this is related to the postbacking going on. That posting back is overwriting the selectedValues with null or something.

<asp:FormView ID="courseUpdateFormView" runat="server" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataKeyNames="CTECourseID" DataSourceID="formviewSqlDataSource" Width="715px">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<table align="center" width="700" border="1" cellpadding="10" cellspacing="2" bgcolor="White">
<%--A whole bunch of textboxes goes here--%>
<td bgcolor="#dadada">
<strong>Number of HS Credits:</strong> <span>(Standards-based districts use the <em>Other</em> form field.)</span>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect HS Credits from the list or enter Other credits in the form field provided.</font></span><br />
<asp:DropDownList ID="numHSCreditsDropDownList" runat="server" TabIndex="3" ToolTip="Standards Based districts us the Other form field." ValidationGroup="HSCredits" AppendDataBoundItems="True" OnSelectedIndexChanged="numHSCreditsDropDownList_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<td bgcolor="#dadada">
<strong>Career Cluster:</strong>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Career Cluster from the list.</font></span><br />
<asp:DropDownList ID="careerCluster" runat="server" AutoPostBack="True" TabIndex="4">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<asp:ListItem Value="1">Agriculture, Food & Natural Resources</asp:ListItem>
<asp:ListItem Value="2">Architecture & Construction</asp:ListItem>
<td bgcolor="#dadada">
<strong>Pathways:</strong> <span>(Pathway as defined in the Cluster/Pathway model.)</span>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Course Pathway from the list or enter Other Pathway in the form field provided.</font></span><br />
<asp:ListBox ID="pathwayListBox" runat="server" DataSourceID="CTECourses" DataTextField="ClusterPathway" DataValueField="ClusterPathway" SelectionMode="Multiple" Style="margin-left: 0px" TabIndex="5" Rows="3">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<asp:SqlDataSource ID="CTECourses" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [ClusterName], [ClusterPathwayID], [ClusterPathway], [ClusterCode] FROM [lkClustersPathways]
WHERE ([ClusterCode] = @ClusterCode)">
<asp:ControlParameter ControlID="careerCluster" Name="ClusterCode" PropertyName="SelectedValue" Type="Int32" />
<td align="center" bgcolor="#4A3C8C" colspan="2">
<asp:Label ID="occupationalStandardsLabel" runat="server" Font-Bold="True" ForeColor="White" Text="Occupational Standards"></asp:Label>
<td bgcolor="#dadada">
<strong>Source of Occupational Standards:</strong>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Source of Occupational Standards from the list or enter Other Source of Occupational Standards in the form field provided.</font></span><br />
<asp:DropDownList ID="tsaOrgsDropDownList" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="TSAOrganization" DataValueField="TSAOrgID">
<asp:ListItem Selected="True">--Choose One--</asp:ListItem>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAOrgID], [TSAOrganization] FROM [lkTSAOrgs] WHERE ([TSAClusterID] = @TSAClusterID)">
<asp:ControlParameter ControlID="careerCluster" Name="TSAClusterID" PropertyName="SelectedValue" Type="Int32" />
<%--A whole bunch of textboxes, checkboxes and other stuff goes here--%>
<td bgcolor="#dadada">
<strong>What is the Summative Assessment (Technical Skills Assessment) for this course:?</strong>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Summative Assessment from the list or enter Other Summative Assessment in the form field provided.</font></span><br />
<asp:DropDownList ID="tsaDropDownList" runat="server" AutoPostBack="false" DataSourceID="TSAs" DataTextField="TSA" DataValueField="TSAID" Width="300">
<asp:SqlDataSource ID="TSAs" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAID], [TSA] FROM [lkTSAs] WHERE ([TSAOrgID] = @TSAOrgID)">
<asp:ControlParameter ControlID="tsaOrgsDropDownList" Name="TSAOrgID" PropertyName="SelectedValue" Type="Int32" />
<%--A whole bunch of textboxes goes here--%>
<td align="center" bgcolor="#dadada">
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<br />
<span><font color="maroon">* All fields except the Tech Prep Information are required.</font></span></div>
<td align="center" bgcolor="#dadada">
<asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
<asp:SqlDataSource ID="formviewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT * FROM tblCTECourses WHERE (CTECourseID = @CTECourseID)" UpdateCommand="UPDATE tblCTECourses
SET HSCredits = @HSCredits, CareerCluster = @CareerCluster, Pathways = @Pathways, TSAOrgs = @TSAOrgs, TSA = @TSA, LastUpdate = GETDATE() WHERE (CTECourseID = @CTECourseID)">
<asp:SessionParameter Name="CTECourseID" SessionField="CTECourseID" Type="Int32" />
<asp:FormParameter FormField="numHSCreditsDropDownList" Name="HSCredits" Type="String" />
<asp:FormParameter FormField="HSCreditsOtherTextBox" Name="HSCreditsOther" Type="String" />
<asp:FormParameter FormField="careerCluster" Name="CareerCluster" Type="Int32" />
<asp:FormParameter FormField="pathwayListBox" Name="Pathways" Type="String" />
<asp:FormParameter FormField="tsaOrgsDropDownList" Name="TSAOrgs" Type="Int32" />
<asp:FormParameter FormField="tsaDropDownList" Name="TSA" Type="String" />
<asp:FormParameter FormField="TSAOtherTextBox" Name="TSAOther" Type="String" />

In the codebehind I've tried to set selectedvalue to session variable upon selected index changed like this:

Protected Sub numHSCreditsDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("HSCredit") = DirectCast(courseUpdateFormView.FindControl("numHSCreditsDropDownList"), DropDownList).SelectedValue
End Sub

View 5 Replies

Forms Data Controls :: Adding Values From Different Database Rows To A Dropdownlist?

Feb 11, 2010

Is it possible to add values from different database rows to a dropdownlist?

I'm currently trying to add both ItemSizeSmall and ItemSizeMedium, but through trial and error I can still only add one row from the database. I want the dropdownlist to display "Small" and "Medium" etc.

I guess my primary question is: How do I create a database with product size attributes?

I apologize if this thread should be in another forum, but if the dropdownlist can display two database rows I'll settle with that solution.

Could the database look like this:

table1: product
PK: productID
table2: productAttribute
PK: productID
PK: attributeValueID
table3: attributeValue
PK: attributeValueID
FK1: attributeNameID
table4: attribute
PK: attributeNameID

If this is right: How do I make the dropdownlist display the different sizes?

View 6 Replies

Forms Data Controls :: DetailsView: DropDownList Keeps Getting Original Values (user Selection Is Ignored)

Feb 17, 2011

I have EntityDataSource for DetailsView which is in Edit mode by default (showin Update, Cancel link buttons).

This datasource also has foreign key called PecID. If I change the value in textbox bound to PecID, it works fine.
Entering IDs is not very user friendly, so I add dropdownlist and new datasource.

When I select new value from dropDownList and press update the DropDownList's selection is restored to original (previous) value.
Other values in textboxes are saved as expected.

After few hours of trying to figure out what is going on, I got lucky. I figure out that it is important the order of TextBox and DropDownList in field template.

This is the working order (textbox before DropDownList)


This one doesn't work [Code]....

View 2 Replies

Forms Data Controls :: Maintaining Selected Values In DropDownList While Paging In GridView

Jan 8, 2011

I have a problem with keeping the selected values in DropDownLists in rows in GridView while paging. I have this code behind:

private void RememberOldValues()
ArrayList LinijaIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in GridView1.Rows)
index = (int)GridView1.DataKeys[row.RowIndex].Value;
if (Session["equal_ITEMS"] != null)
LinijaIDList = (ArrayList)Session["equal_ITEMS"];
if (row.Cells[0].Text == lineTextBox.Text)
if (!LinijaIDList.Contains(index))
if (LinijaIDList != null && LinijaIDList.Count > 0)
Session["equal_ITEMS"] = LinijaIDList;
protected void Button1_Click(object sender, EventArgs e)
//Session["equal_ITEMS"] = null;
GridView1.AllowPaging = false;
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("LinijaID", typeof(int)));
dt.Columns.Add(new DataColumn("Ime", typeof(string)));
ArrayList LinijaIDList = (ArrayList)Session["equal_ITEMS"];
//if (LinijaIDList!=null)
foreach (int LinijaID in LinijaIDList)
foreach (GridViewRow row in GridView1.Rows)
DropDownList Ime = GridView1.FooterRow.FindControl("ImeDropDownList") as DropDownList;
int rowID = (int)GridView1.DataKeys[row.RowIndex].Value;
//string Name = row.Cells[1].Text;
string Name = Ime.SelectedValue;
if (rowID == LinijaID)
DataRow dr = dt.NewRow();
dr["LinijaID"] = LinijaID;
dr["Ime"] = Name;
GridView1.AllowPaging = true;
Session["equal1"] = dt;
// else
// GridView1.AllowPaging = true;
// Session["equal1"]=null;
// }

When I insert a value in the TextBox2 and want to select only the rows from the GridView from different pages which have value in the first column the same as the value in the TextBox2, after clicking on Button1 I get this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


View 3 Replies

Forms Data Controls :: Dropdownlist In A Formview - Insert Fails Because Of Null Values?

Jan 5, 2010

I have a formview on a web page, set to insert mode as default. The form view is bound to a SQLDatasource. This datasource has a custom query written to select the details for this formview. The query joins two tables to provide relevant detail and not just an ID for one of the elements on the form view.

The first tabe contains information regarding projects and the second table contains detail regarding Resources. First table has the following definition:


View 10 Replies

Forms Data Controls :: Access Values Of Dropdownlist Of DgChildren Inside DgParents?

May 12, 2010

I have a datagrid "dgParents" and inside this datagrid I have another datagrid "dgChildren".

In dgChildren I have three dropdownlist drp1, drp2, drp3.

I have a button"Save"

I am able to populate data.

Now User selects any value from dropdownlist of dgChildren and click button "Save".

I have a function in code behind for button click here I want to access the values of drpdownlists that are in dgChildren so that I can save in thesevalues in db.

I'm not able to acess the vlues of dropdownlists that are in dgChildren.

I tries findcontrol and controls etc but didnt work.

I'll really appreciate any help for sample code/tutorial/.

View 3 Replies

Forms Data Controls :: Check Values In A Databound Dropdownlist When Opening A Page?

Jan 22, 2010

I want to accomplish is to check the value of a field against the values within a databound dropdownlist.


View 13 Replies

DataSource Controls :: DropDownList With Static And Dynamic Data?

Jan 8, 2010

I have several dropdownlists which are databound to a SQL DB but I am also needing to add 2 items to them. I am using the code below.

With the code in the Calendar1_SelectionChanged sub (Which is when I want it to fire) It loads the data from the sql but not the static content

If I move the code to the Page_Load sub and add "If Page.IsPostBack Then" then it loads the static content but not the SQL.


View 5 Replies

Forms Data Controls :: How To Add Lookup Table Values To A DropDownList And Bind To A FKValue In The Grid

Jan 26, 2011

I have a GridView control that has a SQLDataSource.

The GridView provides me with a list of musical artists (from the tblArtists)

In the Grid, I have a field, FKGenreID, that is a Foreign Key value for music Genres.

(An example of the data in that field would be "7", which upon lookup would mean Classical in the
tblGenreList table.)

What I'd like to do is add a DropDownList control that looks up the tblGenreList table and populates the DropDownList with the ID and Description from the tblGenreList Lookup table.

Now the tricky part is that if the GridView field (FKGenreID) has a value, then I'd like the corresponding Genre Description to be displayed in the DropDownList

Alternately, if there is no value for FKGenreID in the GridView, then I'd like the DropDownList to show that nothing was selected, but have the list of Genres available.

Most importantly here, when the user makes a selection, I'd like the GenreID (from the DropDownList) to be entered into the FKGenreID field in the GridView field.

My thought is that a gridview record may or may not have a value in the FKGenreID field. Either way, the DropDownList is bound to that field. The DropDownList would display a list ofGenre Descriptions for the user to select from. Upon selection, the GenreID column of the DropDownList becomes the value in for the FKGenreID field in the GridView.

Is this possible?

In case it matters, I'm using ASP.NET 4, Visual Studio 2010, and coding in VB

View 1 Replies

Copyrights 2005-15, All rights reserved