how to auto insert the value of multiple records into dropdownlist base on user selection in c#

Hi,

I have one gridview with column emp#, status.   'status' column is a dropdownlist with 3 types of status for user to select, that is 'approve,disapprove,onhold'.  By default system will set status as 'onhold'.  Example of gridview data as below:

Emp#        Status(dropdownlist)        

001           onhold           

002           onhold

002           onhold

The idea is that the user don't want to select status of dropdownlist one by one if there's a repeated emp#.   Take an example for emp#002, if user select status 'disapprove', then the system will assign the value disapprove to dropdownlist for those records with emp#002.  Is it possible to do that?  Pls help!

 

0
htmlforums
10/24/2008 9:24:26 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
822 Views

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

Hello,

not sure, but have you tried to using AJAX and in the dropdown postback, you'll set other dropdowns of the same EMP to the same value?

0
stealth_pt
10/24/2008 12:46:31 PM

Hi,

I have a select link in each row of the gridview.  If i click select link it redirect to another page. But when i click OTHER column, not the select column , i want it to perform another task base on the particular row that i click.  Can this be done?    My understanding is that, if we put a select command field on it, and user click the select link, we can get the row index and the value of each cell, but how to do this if user click on the dropdownlist on other column and at the same time be able to get the rowindex and value of each cell. ?

0
htmlforums
10/28/2008 9:21:12 AM

Hi,

Based on my understanding, the main issue is how to get the index of the row in which the DropDownList's SelectedIndexChanged event fired.

We can fulfill the task as below:

1. Set the DropDownList control's AutoPostBack to "true".

2. Use page.Request.Params.Get("__EVENTTARGET") method to get the name of the control which caused postback.

    For more information about how to determine which control caused PostBack on ASP.NET page, please refer to :

    http://www.aspdotnetfaq.com/Faq/How-to-determine-which-Control-caused-PostBack-on-ASP-NET-page.aspx

3. Get the index the row by comparing the row's DropDownList control's UniqueID with the postback control's name.

The following code demonstrates how to do this. Please refer to it:

 

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            Control ctl = GridView1.Rows[i].FindControl("DropDownList1");
            if (ctl != null)
            {
               // str is the name of the control which caused postback.
              string str = Page.Request.Params.Get("__EVENTTARGET");
              if (ctl.UniqueID.CompareTo(str) == 0)
              { 
                  DropDownList ddl=(DropDownList)Page.FindControl(str);
                  Response.Write("The index of the row is: "+i+"<br />");
                  Response.Write("The selected value is: "+ ddl.SelectedItem.Value); 
              }
                
            }
        }
    }
   
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="id" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" 
                    SortExpression="id" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
                        <asp:ListItem>a</asp:ListItem>
                        <asp:ListItem>b</asp:ListItem>
                        <asp:ListItem>c</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT * FROM [students]"></asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
 

Forward Sun
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Forward
10/29/2008 5:31:52 PM
Reply:

Similar Artilces:

Form: Focus on selected values in dropdownlists, Refresh after selection and hidding formfields based on selection.
Hello again,I have a form with several dropdown lists. Depending on the selected value in the dropdown lists other fields become available in that same form. It is working in classic ASP in combination of JavaScript. I want to migrate it to ASP.NET. I have posted a part of the form at the end of this post.My questions:1. I use <option <%If iFood="0" then%>selected<%End If%> value="0">No value selected</OPTION> to select the selected item when the form is reloaded after the selecting. I know that this also works in ASP.NET, but isn't there a typical ASP....

Multiple values for multiple items insert using c#.net
Hello, I have an application that allows the user to insert multiple values all related to the same item that reside in multiple tables. example base information, style general details, parts of a style etc. a single table binds them all together using foreignkeyid's. This is kind of a slow process, because they might have to create a set of styles in different colors etc on the same day. say 15 items which are different only in color. Now, I' m having to design a form which will let them insert all 15 items at once.  I dont know how to show you the lay out I have?? My idea abo...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

Insert multiple values(multiple columns) based on single dropdown list selection.
What I would like to accomplish:  I have a dropdown list that is an entityref(populated by values from PK in separate table). When user makes selection in dropdown list, then clicks “Insert”, I would like the selected value to be inserted into the applicable FK column, but also would like to have a value equal to the integer selected, multiplied by 50, inserted into another column of the same table. Example with user selecting “2” in the dropdown list, inserting into Table b:table a: Column: Numbers(PK) (1, 2, 4, 8) Table b: Processors(FK) Inserted: “2”Table b: Factor Inserted: ...

VB.NET
I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateComm...

populating a dropdownlist of states based on selection of country in dropdownlist and populating a dropdownlist of cities based on selection state in state dropdownlist
My code is this but i m not getting states in dropdownlist of states based on selection of country and  cities based on selection of state <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"><title>Untitled Page</title> </head> <...

How to view a form when particular user is selected from DropDownList? (Based on Role)
I am going to school for programming and started working as a programmer very recently. So many things is yet to figure. I've spent countles hours trying to find answers on the web about this and I will appreciate any help. The dropdown with datasource (from sql) is consists of managers. The manager has to be able to create a new form. Next time when manager comes back and wants to view created form(s) he chooses his name from dropdown list and able to view, update, delete....... created by him form.  All this has to be a Role related. Manager: only be ...

Selecting a ListItem in DropDownList based upon a record's value?
This should be easy but the solution escapes me. I have a Form where the user can enter data and it INSERTs the data into a database table. Along with standard TextBoxes, I have a DDL which the user makes one of two choices. The data is then saved into a table and the value from the DDL is a 1 or a 2. Easy enough. I then have a very similar form the user can edit/update their data. But I'd like the DDL to read the data in the record's field and preselect the appropriate ListItem instead of defaulting to the first choice. Make sense? How can I do this? Here's my DropDown...

In FormView Insert mode, how to retrieve the value of a field based on the selection in a dropdownlist.
I am using a FormView to update an Access database.  I have the Update and Delete functions working correctly.  However, when the FormView is in Insert mode I need to retrieve a value from a different Access table (a Lookups table) based on the value selected in a DropDownList on the FormView before the record is committed to the Access database..  I've tried various approaches (OnSelectedIndexChanged, OnTextChanged, etc.) but I can't seem to get this to work. For example, if the FormView has two fields bound to an AccessDataSource, the user m...

How to Pass data to pop up form, allow user to add new value, pass new value back to form to do Insert
I have a grid view that shows the user the last meter readings (hours) for several generators. The meter readings need to be added daily.  I would like the user to be able to select the meter record from the grid view and have a pop up javascript form open that would allow the user to enter a new meter reading. Then after I do validation, do an insert of the new reading to the database. Is that a reasonable way of doing what I want? If not, can you give me a suggestion as to how to do it differently. Thanks. Hi..   Instead of opening window to ente...

DropDownList value selected base on database value?
Hi, is there anyway how I can allow my dropdownlist (on pageload event) to select the value base on the value found in the database, in addition I also want the dropdownlist to contain other values too however the selectedValue must be the one found in the database. Sorry if it sounds confusing. I'm using VB.NET 2003 with ASP.NET Thanks. Hi,Whatever you want to get selected for your dropdown use following code.if(dropdownid.items.findbyvalue("value") != null){    dropdownid.items.selecteditem = false;    dropdownid.items.findbyvalue("value").selected = t...

Web Menus / User controls in aspx web page and .aspx C# based web templates
Dear all, I have created several user controls and included in the webpages. (This user control is a navigation menu consisting of images) This has to be included in all webpages. But when i tried to publish i get error messages for them. But i can’t remove since i need these user controls. Error message given below Error 2 The type 'WebUserControl' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\new_latest\d203e69a\d67c356f\App_Web_ijsq-eqk.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\new_la...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Based on selected value from HTML.Dropdownlist, the values to be fetched
Hi,  I'm using Html.DropDownList.  When selection within this box changes, I need to retrieve the values from table based on the selected id(datavaluefield) of dropdownlist. Here my code ViewPost.cs viewpage <%=Html.DropDownList("CategoryID",ViewData["CategoryID"])%>  ---- based on selected value from the user the below table should fetch the value the db <table>        <tr>                   ...

Web resources about - how to auto insert the value of multiple records into dropdownlist base on user selection in c# - asp.net.web-forms

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 11/25/2015 7:18:24 PM