VS 2010 - Dropdownlist Getting Index
Feb 13, 2013
I've made a small site which purpose is to allow people to add members to their clan. The page has a dropdown list with the names of all available clans.
The name of the clans and the clan password come from a text file which is read when loading the page (but not when there's a page postback) and adds the clans to the dropdownlist.
The clan name and clan password are also read into an array for later use.
When the user selects an item in the dropdownlist I want to get the index so I know which clan name to use and which password.
I tried getting the index by using the indexchanged event and also just the click event of a button but somehow this doesn't seem to be working properly.
When the user filled in all fields and hits the submit button I want to check if the password is correct and want to know the clanname. I'm trying to do this by using the array's with that data and setting the item of the array equal to the index of the selected item in the dropdownlist.
But when I press the button I keep getting a wrong password error even though it's correct. If I remove the password check and submit it then the form should create or append to a text file with the name of the clan. But when submitted the text files is .txt instead of clanname.txt.
Tried setting the dropdown to autopost back or without and get the same result.
My code is the following:
reading the data into the array + adding the clannames to the dropdownlist
vb Code:
Dim data() As String Dim clanname(50) As String
Dim clanpass(50) As String Protected Sub Page_Load(sender As Object, e As System.EventArgs)
Handles Me.Load
Dim fileName As String = "C:/ClientSites/data/clans.txt"
[Code] ....
The submit button code
vb Code:
Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
naam = txtMemberName.Text.ToString gamertag = txtGamerTag.Text.ToString
platform = txtPlatform.Text.ToString index = DropDownList1.SelectedIndex
paswoord = clanpass(index)
[Code] ....
In short I load in data from a file into two arrays, clanpass and clanname. Populate the dropdown with the clannames. Then upon submitting I want to check the password against the password for the selected item by using it's index. I also want the name to write it to the correct text file.
View 8 Replies
Similar Messages:
Jun 27, 2014
I have a SQL table used by a third party application that I have very little control over. The table contains a list of assemblies and their corresponding serial numbers. The tables primary key is a composite of the assembly number and serial number. There is no field I can use, reliably as an index.
I have an application I'm working on that pulls all the serial numbers from that table based on the assembly in a SQL View. I've then written code that pulls the serial numbers from that view based on the part number in a textbox on the form. That functionality works fine but I had both my datatextfield and datavaluefield set to the serial number. I've created another empty listbox that I would like to populate from a serial number or serial numbers being selected in the first. That is not working, I believe, because there is no index for the list.
My question is...How can I add an index value to each serial number as they populate from the SQL table. I've included the code below that I have pulling the serial number values.
This is an ASP.net VB webform.
Code:
Private Sub FillSnAvailList()
Dim strconnect1 As String = ("Data Source=MyDataSource")
Dim con1 As New SqlConnection(strconnect1)
con1.Open()
Dim cmd1 As New SqlCommand("SELECT [sPartNum], [SerialNum] FROM [V_MaxSerialNum] WHERE ([sPartNum] = @sPartNum)", con1)
[Code] ....
View 3 Replies
May 28, 2010
I want to get the value of the specified index in a DropDownList
View 1 Replies
Feb 16, 2011
I have a populated DropDownList. How do I find the index whose Text value is "x"?
View 1 Replies
Oct 12, 2010
i have 2 drop down list..first for city and second for state i want to fill the state list when the city is selected...m using the code
protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
{
String sqlQuery="select SM.StateId,StateName From StateMast SM,CityMast CM where CM.StateId=SM.StateId AND CM.CItyId='"+ Convert.ToInt16(DdlCity.SelectedValue.ToString())+"'";
DdlState.DataSource = cls.Select(sqlQuery);
DdlState.DataTextField = "StateName";
DdlState.DataValueField = "StateId";
}
but nothing is happing on selecting city..i have set the autopostback of city=true..select is a function which is returning data tablepublic DataTable Select(String sqlQuery)
{
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery,con);
DataTable table = new DataTable();
adapter.Fill(table);
con.Close();
return table;
}
View 2 Replies
Oct 18, 2010
Iam using a dropdown list ,in that am having 4 values ,the following are my values
Uk-L1
Us-L1B
Aus-BUssness
Uk-HSMP
and here i need to choose the a particular value as a selected index ,and i did that for a exact value and in my requirement i will pass only the values after that '-' .so that i need get the value to be selected and here am using the following code to select it is not working can any one help for this.
Code:
DropList.SelectedIndex = DropList.Items.IndexOf(DropList.Items.FindByValue("L1"));
View 1 Replies
Apr 15, 2010
how to get the value from a dropdownlist using a index number.
for example i want to show in a label the the value of the item in dropdownlist whose index is 5
View 5 Replies
Jul 29, 2012
i have 2 drop down list on my web page
-the first one bound to a sqldatasource and it's work fine
-the second one bound to a sqldatasource (with a parameter depends on the first drop down list selected value )and it's work fine too .
But when a user make a selection on the second drop down list, any post back on the page will return the second drop down list selected index equal to 0.I tried so hard (ON MSDN) to understand why this happen only on this drop down list.
View 4 Replies
Feb 1, 2011
Im working on an ASP.Net web forms application, where I have a form and the Index is working correctly, until I select a value from one specific control, a dropdownlist. After that no matter what control I am on if I press TAB it will go to the URL/Address Bar, from there to the search bar and then again to the URL bar...
View 1 Replies
Jun 7, 2010
i have a user control that includes a dropdown list its actually a page navigator when the user press next page iam setting the index of the selector to the value of a hidden textbox where textbox is filled from javascript function. ex txtbox initially is 1. then when next pressed it is 2 and so on but when doing postbacks i.e pressing next it is not changing the index although in the debuy its showing its setting to the new value. as if there is something that is reseting it to the initial value after the page loads if i put my method in the prerender method its working fine. but in the page_load method its not updating to the new index changed. i need to put it in the page_load method as i have to register some event handlers for the navigator.
View 5 Replies
Jun 15, 2010
I have Created A Custom Control which is a DropDownList with specified Items. I designed AutoPostback and SelectedCategoryId as Properties and SelectedIndexChanged as Event for My Custom Control. Here Is My ASCX file Behind Code:
private int _selectedCategoryId;
private bool _autoPostback = false;
public event EventHandler SelectedIndexChanged;
public void BindData()
[Code]....
But Always The Selected Index of CategoryDDL1 is 0(Like default). this means Only Zero Value will pass to the event to update textboxes Data. what is the wrong with my code? why the selected Index not Changing?
View 1 Replies
Jul 12, 2012
I am using SelectedIndexChanged in the DropDowList and it works fine and populates a GridView based upon a site selection.
Is there there a way I can reset the SelectedIndexChanged so if user wants to refresh the GridView they would open the drop down list and click on the same selection again?
View 5 Replies
Jan 26, 2012
I am populating a DropDownList from a text file (class requirement).
The file is read in the Page_Load method and the DropDownList is populated then.
When I press the Submit button, throughout the process of the code it is supposed to get the SelectedIndex and use it to grab a value out of a List(Of ).
The thing is, nothing is ever passed through. I even setup an alert box and it passes right over the alert box and never even triggers it, but gives me an Index out of range error when it moves to the line right after the Alert.
Code:
Redacted to keep people from stealing classwork.
View 6 Replies
Apr 28, 2014
<br />
<table align="center">
<tr>
<td>
<fieldset>
<legend>
[code]...
For Edit I want to select the OfficeName before Selecting a Department or any another way to do this
View 1 Replies
Feb 8, 2011
I have a problem in setting the selected index /value in a drop down list. The list is bound by a Linq query and I want to add an item at the top of the list and set it as the selected item.
THis is the code i am using
ListItem li = new ListItem("Select", "", true);
list.DataSource = (from ap in edc.Approvers
where ! ap.approverEmail.Equals("")
orderby ap.approverEmail
select new {ap.approverEmail}).Distinct();
list.DataTextField = "approverEmail";
list.DataValueField = "approverEmail";
list.DataBind();
list.Items.Add(li);
list.Items.FindByText("Select").Selected = true;
The listItem li is the item i want to be first in the list and also selected. Adding this before the databind just loses the item.
View 2 Replies
Dec 4, 2010
I have a user control that has some drop down lists. These DDLs are used by the user to filter their product search on my search page. A button is used to post the form and get the results of the product search. Those results are displayed on the results page, which also has the search filter user control on it. I'd like the results page to have the values of the DDLs be preserved from the search page. Example: user selected color of red and size of large on the search page. When the results page is displayed, I'd like the selected color to be red for the color DDL and the size to be large for the size DDL. How can I do this?
View 9 Replies
Sep 13, 2010
I have a dropdownlist1 control in footer template, but when i go to edit command for editing an existing row. at that time. the footer dropdownlist box showing exact index which is selected in edit template dropdownlist box.
dropdownlist1 is in footer template and dropdownlist2 is in edit item template.
same datagrtid i am using for adding new rows via footer template and editing existing rows via edititem template.
how to make dropdownlist1 which is in footer template to selectedindex "0", when i go to editcommand. tried using itemdatabound but not working.
View 4 Replies
Jan 17, 2010
Ok i have a dropdownlist inside a formview.When i select to update the formview the dropdownlist will automatically go to the first item on the list.
Is it possible to keep the item that is currently selected before i go to the update formview page?
I can get the dropdownlist from the formview with Findcontrols but then?
P.S. My dropdownlist is declared inside the formview
[Code]....
View 5 Replies
Aug 30, 2012
How to select next row of grid view on selected index change event on dropdownlist in gridview...
View 1 Replies
Sep 30, 2013
i have on dropdown, i want to set specific selected item at top of dropdownlist box when binding items inside dropdowlistbox.
View 1 Replies
Feb 23, 2013
there is 3 drop down list control in in first dropdown load Districts when page load when we select or index changed in drop down1 items changed or loaded in drop down list2 according to the disrict.According to the item selected in drop downlist2 items changed or loaded in drop downlist3.
View 1 Replies
Mar 16, 2011
I am trying to capture the SelectedIndexChanged event for a drop down list I have put inside of a gridview control. It posts back fine, but does not go into my SelectedIndexChanged event handler. Here is my code
[Code]....
it is still not going into my myddl_SelectedIndexChanged() eventhandler.
View 1 Replies
Mar 20, 2011
I have a simple query based on the index changed event of a dropdownlist in ASP.NET. The scenario is i have a dropdown list bearing a collection of items (say ONE, TWO, THREE, FOUR, FIVE) with the default value selected as 'ONE'. Now, when the client changes the index (say the client selects 'TWO'), a confirmation box is prompted asking 'Are you sure want to change the index?' with the buttons YES & NO. Now, the problem is, if YES button is clicked then its working fine as the index is changed. But when NO button is clicked in the confirmation box, I do not want the index to be changed to 'TWO' and it should be holding the previously selected value which was 'ONE'. How can I do this? For which event should I write the code, as I cant think of writing the code for the IndexChanged event because here the index change has already occured and since there is no 'IndexChanging' event in ASP.NET, where shall i write the code
View 7 Replies
May 7, 2015
In ASP.NET, I can get the selected index of dropdownlist using:
var dropdown1 = document.getElementById('dropdown1');But I want the selected index of that dropdownlist, which is present INSIDE a GridView.How to get that using JavaScript?
View 1 Replies
Jan 5, 2014
I want to create a drop down list, where user can view the code name and the name the code when they click on the drop down list.
But after they choose, only the code is appeared. This is my current coding as for now.
<asp:DropDownList ID="ddlcodetype" runat="server">
<asp:ListItem Selected="True">-</asp:ListItem>
<asp:ListItem>DK Deck</asp:ListItem>
<asp:ListItem>EG Engine</asp:ListItem>
<asp:ListItem>CT Catering</asp:ListItem>
<asp:ListItem>OT Others</asp:ListItem>
</asp:DropDownList>
With this, both my name and the code name are appeared.
View 1 Replies