dropdown selected value and dropdown no value saved

 is there any way the selected value is selected already when i try to edit the gridview ...

and another thing... when i edit this dropdown.. no value was being saved... 
what is wrong or missing.. please help... i almost spend two days on this problem...
i've read many post about this.. but still i didn;t get it... please help/// 
 

<asp:TemplateField HeaderText="Unit" SortExpression="UnitID">
                            <EditItemTemplate>
                                <asp:DropDownList ID="drpUnit1" runat="server" Width="80px" >
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblUnit" runat="server" Text='<%# Bind("UnitID") %>'></asp:Label>
                            </ItemTemplate>
 </asp:TemplateField>

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim drpUnit1 As DropDownList
Dim lblUnit As Label

If Not IsNothing(e.Row.FindControl("drpUnit1")) Then
drpUnit1 = CType(e.Row.FindControl("drpUnit1"), DropDownList)
lblUnit = CType(e.Row.FindControl("lblUnit"), Label)
drpUnit1.DataSourceID = "sqlDrpUnit"
drpUnit1.DataTextField = "Unit"
drpUnit1.DataValueField = "UnitID"

drpUnit1.DataBind()

End If

End Sub

Protected Sub View2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles View2.Load


'DropDown Unit
sqlDrpUnit.ConnectionString = conn
sqlDrpUnit.SelectCommand = "SELECT [Description] AS Unit, [LookUpID] AS UnitID FROM [Lookup] WHERE [CategoryID] = 4"
sqlDrpUnit.SelectCommandType = SqlDataSourceCommandType.Text

End Sub
 

 


Regards,
Mhaey

Please remember to click “Mark as Answer” on the post that helps you.. =)
0
darkcat02
5/19/2008 3:24:33 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
729 Views

Similar Articles

[PageSpeed] 21

you are binding data everytime a row is loaded in the gridview

drpUnit1.DataBind()

bind it on load. or for a specific event, here if there are 30 rows you are binding 30 times....

 

more here

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx



Joël Hébert [MVP ASP.NET]

Opulent ASP Development Inc.
www.opulentasp.com
Ottawa,Canada

Click "Mark as Answer" on the posts that helped you to help future readers to get the solutions
0
Joël
5/19/2008 3:51:23 AM

While Binding Dropdown u must specift selected value

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim drpUnit1 As DropDownList
        Dim lblUnit As Label

        If Not IsNothing(e.Row.FindControl("drpUnit1")) Then
            drpUnit1 = CType(e.Row.FindControl("drpUnit1"), DropDownList)
            lblUnit = CType(e.Row.FindControl("lblUnit"), Label)
            drpUnit1.DataSourceID = "sqlDrpUnit"
            drpUnit1.DataTextField = "Unit"
            drpUnit1.DataValueField = "UnitID"

            drpUnit1.DataBind()
           drpUnit1.SelectedValue ="XYZ"
        End If

    End Sub


No body is perfect, I'm nobody
0
saifi_hasan
5/19/2008 4:34:46 AM

saifi_hasan@yahoo.co.in:

While Binding Dropdown u must specift selected value

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim drpUnit1 As DropDownList
        Dim lblUnit As Label

        If Not IsNothing(e.Row.FindControl("drpUnit1")) Then
            drpUnit1 = CType(e.Row.FindControl("drpUnit1"), DropDownList)
            lblUnit = CType(e.Row.FindControl("lblUnit"), Label)
            drpUnit1.DataSourceID = "sqlDrpUnit"
            drpUnit1.DataTextField = "Unit"
            drpUnit1.DataValueField = "UnitID"

            drpUnit1.DataBind()
           drpUnit1.SelectedValue ="XYZ"
        End If

    End Sub

 

 

i always get this error... 

 

'drpUnit1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
 


Regards,
Mhaey

Please remember to click “Mark as Answer” on the post that helps you.. =)
0
darkcat02
5/19/2008 5:55:04 AM

Joël Hébert:

you are binding data everytime a row is loaded in the gridview

drpUnit1.DataBind()

bind it on load. or for a specific event, here if there are 30 rows you are binding 30 times....

 

more here

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx


 

 

hmm..ive already put an onrowdatabound... i still got an error on the selected value... still didnt know if i get a value..

but... when i put the datasource and etc. in the aspx page.. there are no errors... i really want this problem of mine to be solved... 


Regards,
Mhaey

Please remember to click “Mark as Answer” on the post that helps you.. =)
0
darkcat02
5/19/2008 5:57:45 AM

Greetings,

i think my solution is that you still you need to use rowdatabound but before binding the dropdownlist you have to check if the row in edit mode because as one of the repliers said that if you have x rows then you are binnding the dropdownlist x times.

i hope that my answer will help you.

Regards. 

0
wissam1
5/19/2008 6:09:09 AM

wissam1:

Greetings,

i think my solution is that you still you need to use rowdatabound but before binding the dropdownlist you have to check if the row in edit mode because as one of the repliers said that if you have x rows then you are binnding the dropdownlist x times.

i hope that my answer will help you.

Regards. 

 

hi there.. im still a student.. i cant understand that much.. but if there will be an example... that would be a great help for me.. thanks 


Regards,
Mhaey

Please remember to click “Mark as Answer” on the post that helps you.. =)
0
darkcat02
5/19/2008 6:23:49 AM
Reply:

Similar Artilces:

hide only the dropdown value while selecting the another dropdown value
 hai  friend i am using two dropdown list if i select one dropdownlist the another dropdownlist value must be hidewhat can i do for this     Ramesh.Dhttp://rameshduraikannu.blogspot.com  u can do that using javascript..function Hide(){ var drop1 = document.getElementById('<%=dropdownlist1.ClientID%>')  var drop2 = document.getElementById('<%=dropdownlist2.ClientID%>')  if(...

Cascading Dropdown - Initially selected value
Hi there, I am having an issue with a pretty basic problem. I have managed to get the cascading drop down lists working ok with information coming from a database. On the initial page, I need to have a value in the drop down list already selected, i.e. the current year in one drop down and current month in the next. The information from both of these is sent to a query to output a datatable. Can anyone help with this? I'm not sure I understand the scenario, but I think the new CascadingDropDownNameValue(..., defaultValue) constructor may be just what you're looking for. (First available ...

Cascading Dropdown List
Hi, First post so hello and need some help with an issue I have been dealing with.  I have an intranet page I created in ASP.NET using C# .NET 3.5 with a few Ajax Extenders including 3 Cascading Dropdown Lists. Now I have used the Cascading dropdown lists for my own purposes i.e they do not actually cascade their results to another dropdown list, the reason I did this was due to the having a User Control that contains an update panel and other bits i.e I didn't want the control/page posting page (something that happens when you click on a regular dropdown list). Everything is wor...

Cascading Dropdown Selected values and Default values
I am loading the cascading dropdown control with data from my database implementing web service methods written in VB, and cascading dropdown control runs fine. Now as in any classic application I would like giving default values to  3 dropdown lists concerned with cascading and also getting back selected entries to call my database to retrieve records with values read as criteria. First I tried to postback with a button control after selecting entries in cascading dropdown control, but the resulting selected values are empty. Can anyone help. Hi, As you click the Button...

adding values to the selected value in Dropdown list
 Hi,   I have dropdown box in my page which have some value inherted from the another list box in my page..Now in my second page , i have dropdown box with values and text value and list box... I'll be selecting the one value from the dropdown then i enter the value in text box and click on add button which will add the value in the list box like this i can able to add many value...now if i click on save button for the selected dropdpown item the added values in the listbox should be saved ...like this i add many values for many dropdown item and saved respectivelynow if c...

Dropdown woes. Need to db value to correspond with dropdown value
I have a dropdown that I need to have set to the selected index of a value thats returned from the DB, an integer that represents the userID. I have the value returned fine but I' struggling to convert it into the number it needs to be to correspond with the dropdown index. I can do it with text items with the following: - Action_DD.SelectedIndex = Action_DD.Items.IndexOf( Action_DD.Items.FindByText(insertJobRow[JobData.NEXT_ACTION_FIELD].ToString())); but i need to do the above for integer values. Any one know how. Have you tried using the FindByValue() method in place of ...

problem in selecting value from dropdown inside a repeater and inserting the selected value inside db
there is  checkbox and drop down inside my  item template of repeater in one page.Based on that drop down and check box selection calculation will be done in another page which will be inserted inside a db.I cannnot fetch the value from the dropp down in my save page  and as a resut data cannot be inserted inside db. plz help!!  <asp:Repeater ID="rptmenproduct" runat="server" >                      <HeaderTemplate>    <...

How to use values from two dropdown lists to get the value for a third dropdown?
I have three dropdown lists.  One for Office, one for Department, and a list of employees.   There is no relationship in the database between office and department.  The relationships are to the employees.  What I need to do is take the selected values from Office and Department, and run a query to get the list of employees who match both parameters (Office & Department).  Here's my code for the three dropdown lists.  How do I "connect" Office & Department to populate employees?  code from my vb.net page    for the ...

How to show value in textbox from selected value in Dropdown list
I have two text box, txtbox1 should be from two field for example i have one dropdownlist where i select item and another txtbox2 i want to put value, when i first time to write manually value in txtbox2 in and selected item from ddl i want to result in concatenate from in txtbox1. for example  I haveif not me.ispostback thenDim cm as new sqlcommand("Select AccMjrid, Names from Accgrp", me.sqlconnection1.open())me.sqldataAdapter1.fill(Dataset1, "Accgrp") Me.cmbAccMajID.DataSource = Me.DataSet11.Tables("AccMajor") Me.cmbAccMajID.DataTextField = "AccName" Me.cmbAccMajID.DataValueField ...

Assigning value from dataset as selected value in cascading dropdowns
hello!  I have successfully implemented the Ajax Cascading Dropdowns but am running into an issue.  I am databinding the available selections to all three of my dropdown lists.  Then I need to make the selected value of each dropdown a value from my dataset.  The selected value works for the first dropdown, but I cannot figure out how to set up the selected values of the other 2 dropdowns.  (This would be values a user has selected previously, not default values.) Can anyone assist me? Thanks in advance!   Hi Stormcadi, As far as I know,  you should d...

DropDown list submits first value not the selected value
I am relatively new to programming and am having a problem with a small project that I am working on.  I have a names drop down list that is created from a database.  When the user selects a name and completes the rest of the form and clicks submit.  All of the data they entered is submitted to a different table in that database.  This is workign correctly for all of the data except the drop down.  For some reason the first value in the drop down is being submitted each time.  Here is the code and any help you can give will be appreciated. Public Class final1 ...

Saving DropDown List Selected Values to database?
Hello everyone.   I'm quite new to ASP, Visual Web Developer, and C#. I've been going over the tutorials trying to absorb everthing I can and I've also been reading up on SQL. Anyways, Im trying to make a web application that I can use to update my database. I've been over the tutorials that demonstrate how to use GridView and Details View to display, update and insert data but I don't think these will work for me as the data I need to update is all based upon a variety of different queries which calculate certain values. Sometimes values are looked u...

Selected Value of dropdown Box in Custom control
Hi Experts, I created a custom control which has Drop down controls as one control. I'm able to set DataSource,DataValueField,DataTextField from the page. But How can I get the Selectedvalue of the DropDown list from that Custom Control. The Dropdown Controls' AutoPostBack is set to false Any Idea on this ..PleaseThanks Vizai Do you expose the DDL from the control as a property? How do you set the DataTextField etc now? Post the code.Thanks,Teemu KeiskiFinland, EU In Custom control I declared properties as b elow   public string DataValueField { get { object o =...

Dropdown with saved value selected, but other options listed?
I've created a vb.net page that a user enters data thru various databound dropdown lists and text boxes.  When the user clicks submit, the data is stored in various tables.  My question is, what if the user made a mistake and wants to return to a vb.net page that looks similiar to the page that they entered data.   How do I display the value they entered as the selected value of the dropdown box, but still provide them with all the other selections for the dropdown box so they can change their entry?  Never make important decisions on a Monday! This really depe...

Web resources about - dropdown selected value and dropdown no value saved - asp.net.presentation-controls

How to convert unordered list into nicely styled <select> dropdown using jquery?
$('ul.selectdropdown').each(function(){ var select=$(document.createElement('select').insertBefore($(this).hide(); $('>li a', this).each(function(){ ...

Credit Suisse Reiterates On Enbridge Energy Partners, L.P. Following Alberta Dropdown
In a report published Thursday, Credit Suisse analyst John Edwards reiterated an Outperform rating on Enbridge Energy Partners, L.P. (NYSE: EEP), ...

Convert a Menu to a Dropdown for Small Screens
Create a menu that, on smaller screens, changes into a dropdown menu. A dropdown takes up much less screen real estate and can be easier to use. ...

Office-Add-in-Fabric-UI-Sample/Dropdown-demos.html at master · OfficeDev/Office-Add-in-Fabric-UI-Sample ...
Contribute to Office-Add-in-Fabric-UI-Sample development by creating an account on GitHub.

Google Adds Dropdown Menu to Search Results, Hides Cached Pages Inside
Google recently updated their search results format, again moving the link for cached page access somewhere else. Now it hides in a convenient ...

50+ Awesome jQuery Dropdown Menu Tutorials
When designing graphical user interfaces, many people prefer to use a dropdown menu as a GUI element. This allows the user to choose a value ...

Sign out command in dropdown
We can save some space in the menus by putting the Sign-out command in the dropdown menu. As we're building the menu, if I see a command called ...

Google toys with removing Instant Preview in Search, adds dropdown menu with Cached, Similar, Share options ...
Google has added a new drop-down menu to its search results page beside every URL with three options: Cached, Similar, and Share. At the same ...

Facebook Fan Page Changes You Haven’t Heard About
... fashion appears at the top center of the page if you scroll down to the cover image or any point lower. A box labeled highlights has a dropdown ...

Edit Companies - Eric Feng - CrunchBase Person Profile
If this person is an investor, please only submit companies for which he/she has a functional role (like Board, Advisor, etc). Click 'Past?' ...

Resources last updated: 11/23/2015 7:22:37 AM