Web Forms :: ListBox Binding Error - Select A Item From LB2 And Click On ADD The Selecteditem Is Added To LB3

Mar 23, 2010

I am having 3 ListBoxs(LB1,LB2,LB3).In LB1 I am binding the names of Courses through database.The code is shon below...

da1 = new SqlDataAdapter("SELECT COURSE_ID,COURSE_NAME FROM Course_Mst", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
lstCourse.DataSource = dt1;
lstCourse.DataValueField = "COURSE_ID";
lstCourse.DataTextField = "COURSE_NAME";
lstCourse.DataBind();

Whenever I select particular course in LB1 all the content related to that course will be binded in LB2.The code is shown below.....

protected void LB1_SelectedIndexChanged(object sender, EventArgs e)
{
da2 = new SqlDataAdapter("SELECT SPEC_ID,SPEC_NAME FROM SPEC_TRANS WHERE COURSE_ID="+Convert.ToInt32(lstCourse.SelectedValue)+"", con);
DataTable dt = new DataTable();
da2.Fill(dt);
lstSpecilization.DataSource = dt;
lstSpecilization.DataValueField = "SPEC_ID";
lstSpecilization.DataTextField = "SPEC_NAME";
lstSpecilization.DataBind();
lstSpecilization.Focus();
}

I am having a ADD button.In LB2 I can select multiple items.When I select multiple items in LB2 and click on ADD all the selected items will be binded into LB3.The code is shown below...

protected void btnAddCourseDetaisl_Click(object sender, EventArgs e)
{
for (int intLoopIndex = 0; intLoopIndex <lstSpecilization.Items.Count ; intLoopIndex++)
{
if (lstSpecilization.Items[intLoopIndex].Selected)
{
ListItem li = new ListItem(lstSpecilization.Items[intLoopIndex].Text, lstSpecilization.Items[intLoopIndex].Value);
LB3.Items.Add(li);
}
}
}

My problem is when I select a item from LB2 and click on ADD the selecteditem is added to LB3 but if I select the same item and click on ADD the items are again added to the LB3.I want to prevent this.Pls respond me ASAP.

View 1 Replies


Similar Messages:

How To Insert A New Item In A Listbox And Then Setfocus On The Listbox New Item On A Button Click Event In C#

Sep 24, 2010

I have a listbox which populated from using a datatable. I have a Add button in my page. On clicking the add button I want to insert a blank row in the listbox. This can be done easily by

ListBox_Admin.Items.Add("");

after this is done I want to select this item as in setfocus on this item.How do I do this.

View 3 Replies

Maintain Added List Item While Binding From Datasource?

May 24, 2010

I have a drop down list, and I added some items in it as follows

<asp:DropDownList ID="ddlInsAuther" runat="server"
DataSourceID="ObjectDataSourceInsAuthers" DataTextField="AutherName"
DataValueField="AutherID">

[code]...

View 1 Replies

Web Forms :: How To Pre Select A Drop Down Listbox Item?

Feb 18, 2011

How can I pre-select a drop down list box item in a listbox? I experimented using Asp.net and C#, but was not able to pre-select a drop down listbox item.

I am not on my coding box right now, but basically as an example of what I am talking about, if I have the following drop down listbox items.

--Select--
New York Jets
New England Patriots
Green Bay Packers
Atlanta Falcons
SF 49'ers
Oakland Raiders

How would I pre select the team name of "Atlanta Falcons" using C# and Asp.net? Spefically based on the string of the team name "Atlanta Falcons" instead of an alternate way like using the Selected Index function?

View 4 Replies

Set Scroll Bar To Selected Item In Multiple Select Listbox

Feb 1, 2010

I have a multiple select Listbox.When I click on it then it post backs and scroll back to the top of the Listbox. Is there any property to prevent it?

View 1 Replies

C# - Changing The SelectedIndex Of Multiple Select Listbox To The Last Selected Item?

Jan 18, 2011

Referring to a C#, .net, System.Web.UI.WebControls.Lisbox which has a multiple select option true and needs to do a postback every time selected index changes.

Problem is, the [SelectedIndex / SelectedItem / SelectedValue] is always on the value of the 1st selected item. Clicking on the second item, third item, does not change the SelectedIndex, causing the listbox to reload and scroll to the highest selected item position.

View 5 Replies

Web Forms :: Listbox.Selected - Duplicate Item Error

Nov 4, 2010

I have built one of those 2 listbox things where the items in the left textbox can be selected and moved to the right list box. The items in the list can be thought of as tasks (like Raise Invoice, Call Client, Deliver goods etc) The rules of this are that the item you move to the right box remains in the left box. Reason being, you are allowed to add the same item from the left to right as many times as you like. An example what the list on the right might look like is this.

Raise Invoice
Call Client
Deliver Goods
Installation
Call Client
Finalize Deal

Now I have added the feature to select an item on the right and hit the UP button, to move it up in the list. For example I could select 'Deliver Goods' and hit the up button. (the down button works as expected)

Raise Invoice
Deliver Goods
Call Client
Installation
Call Client
Finalize Deal

If i select the 2nd instance of Call Client and hit the up button,

Raise Invoice
Call Client
Deliver Goods
Installation
Call Client
Finalize Deal

This is what happens.

Raise Invoice
Call Client
Deliver Goods
Installation
Call Client
Finalize Deal

My code that loops though and does the move relies on the item.selected property to find which on I have selected. (obviously)

[Code]....

Despite having the items at the bottom of the list selected, the .Selected property is true on the first instance of the item that happens to have the same .Text and .Value.

View 1 Replies

Web Forms :: DropDownList Accessing SelectedItem Property After Binding It ?

Oct 28, 2010

So here is the problem , Is it possible to get the "SelectedItem.Text" of a binded dropdownlist? because everytime I'm getting null Even though I'm having
items in the dropdownlist.

I'm getting the items that I want in the dropdownlist but I can't find out which one is selected.

[Code]....

here is my aspx code:

[Code]....

View 3 Replies

Listbox Control Not Preserving Selected Item On Button Click

Mar 26, 2014

Ok so I have two listboxes on my page one for users and another for cases. For some reason the users listbox preserves state, but the cases listbox doesn't.

They're both set EnableViewState= true

Code:

<asp:ListBox ID="ExistingUsers" runat="server" Width="45%" Height="189px"
CssClass="createdusers" ></asp:ListBox>
<asp:ListBox ID="ExistingCases" runat="server" Width="45%" Height="190px"
></asp:ListBox>

I tried setting them both to autopostback, but that didn't work. The users listbox would preserve the selected item, but make it the first viewable item in the list. The cases listbox still reset the selected item to the first.

My page load:

Code:

'....
If Not Page.IsPostBack Then
''Sort later.
Dim i As Integer = 10
For Each usr As String In AttRoleProvider.GetUsersInRole("Role1")
Me.ExistingUsers.Items.Add(usr)

[Code]......

View 4 Replies

Forms Data Controls :: Page.setfocus(listbox.selecteditem) Is Not Setting The Focus If Index > 820?

Sep 13, 2010

Why I am unable to setfocus to my list box if the index > 820

My list box contains 2000 items and the index is not able to set the focus if the index > 820

View 6 Replies

Listbox Selecteditem Error "Object Reference Not Set To An Instance Of An Object"

Jan 28, 2010

There have an error "Object Reference not set to an instance of an object" when using objusername.intuserid=listbox1.selecteditem.value.

View 1 Replies

Web Forms :: Adding Item To Listbox From Another Listbox Taking Way Too Long?

Mar 4, 2010

I have two list boxes, one has a list of available users (about 1500 items) and the other is blank. There is a button to add the seleted items from the first list box to the second one. Both of these listboxes are within an update panel and for some reason it takes over 20 seconds for the items to show up in the second listbox.

Is this normal? Is there an alternate, faster way of doing this?

View 6 Replies

Forms Data Controls :: Custom Binding An Item Template Error - (string)' Has Some Invalid Arguments?

Mar 12, 2011

I have a gridview with item template and I want the text in that item template label to come from a method in a code behind.

Here is my gridview:

[Code]....

[Code]....

[Code]....

I want to call this method but I'm getting the errors: "

"The best overloaded method match for 'employeepayment.RegTime(string)' has some invalid arguments"

"Argument '1': cannot convert from 'object' to 'string'"

Someone know the answer?. I thought I was right to use Eval.

View 2 Replies

How To Select An Item Click Submit And Display The Information From The Database

Jun 10, 2010

really new to the programming scene. writing a program so when i select an item from a drop down list i click the submit button and i want it to display the items selected from the database in a gridview. so in short i want to select an item click submit and i want it to display the information from the database.

View 2 Replies

Forms Data Controls :: Change Selecteditem Of Ddl On Click Button?

Nov 20, 2010

Change selecteditem of ddl on click button

View 2 Replies

Web Forms :: DropDownList SelectedItem Object Reference Not Set Error?

May 27, 2012

Object reference not set to an instance of an object.
 
if((drpdept.SelectedItem.Text != "--Select--")|| (drpdept.SelectedItem.Text !=null))
{


i hve above line but i get Object reference not set 

View 1 Replies

Web Forms :: New Entries Added To Listbox Not Appearing After Postback?

Oct 22, 2010

I have added a listbox, and on page load I populate it with a few items. Then I have added Javascript code so that the client can click a button to add more items to the listbox. But when the page is postedback I am only left with the items that were loaded from the page load....

Is this the way .net operates?

I was reading that if I need to get all the items in the listbox, I will need to add a hidden field and write out the items in a CSV format, and then use that hidden field to work out the items in the listbox..

View 5 Replies

Web Forms :: Dropdownlist Item Added Through Javascript?

Apr 19, 2010

I have a formview that when in insert/edit mode, has a dropdowlist and a linkbutton. The linkbutton opens a popup with another formview that allows the user to enter new items that are required to be added to the dropdownlist. When the popup closes, it adds any new items to the dropdownlist options (there may be more than one item added). The purpose is to prevent having to have my users partially add/update a record, go create a new item for the dropdownlist then have to come back and edit again since any new items won't be known until they are needed.

At first, I recieved the 'invalid postback or callback' warning and began reading up on the issue. Though there were several forum posts and web articles, most seemed a few years old so I thought I would find out if there were any subsequent changes that might help me out. I'm using vwd2005/ASP.Net 2.0 and do not have ajax (not available on my corporate web servers). In the page directives, I disabled EnableEventValidation but then I found that while other controls were updating, the value set in the dropdownlist was not and I had to make 2 edits anyway. Since new items in the ddl won't be around when it is rendered, i've read that I can't make use of registerforeventvalidation. ps. i have thought that i could save my viewstate, browse away from the page instead of use a popup, then restore the viewstate, but I'm concerned about being able to update the ddl while retaining the viewstate.

View 2 Replies

Web Forms :: DropDownList Selected Item Is Lost And Default Item Is Inserted In Database On Button Click

Jul 16, 2012

I bind dropdownlist in my page

protected void Page_Load(object sender, EventArgs e) {
BindDropDownList(DDL1, "city1", "name", "ID");
DDL1.Items.Insert(0, new ListItem("select city", "0"));
}

And SP

LTER procedure [dbo].[city1]
as
begin
select id,Name
from city
end

And design code

 <asp:DropDownList ID="DDL2" runat="server" CssClass="daddsd">
</asp:DropDownList>

And here is imagebutton code that when click on it update data into table

protected void ImageButton_Click1(object sender, ImageClickEventArgs e) {
string data = Server.UrlDecode(Request.QueryString["BehCode2"]);
SqlCommand _cmd = new SqlCommand("insertinfo", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();

[Code] ....

Here when i click on button it insert all data into table but it didn't insert my selected item from dropdownlist it insert select city that i define in page_load

 DDL1.Items.Insert(0, new ListItem("select city", "0"));

And when i delete this code from page load it insert in table first row of my table it didn't insert my selected item from dropdown list.

View 1 Replies

Web Forms :: Binding A Click Events Validation To Whether Another Click Event Has Happened?

Jan 7, 2011

I've been searching a little bit to try and find the answer to this problem. As of right now another person I work with has designed a wizard step with an upload button in part of it. After the person clicks the browse button and selects their file a validation statement comes up saying, "Please click 'upload and continue' or clear the field" and then is supposed to disable the continue button until this is done. He started by adding a RegularExpressionValidator and found it did not solve his problem.

Now that he's out today we're working on trying to solve this and my first though is to actually use a custom validator instead and have it call a function in the back-code for validation which checks to see if the "Upload" click-event has happened. Is there an easy way of verifying whether or not a click-event has occurred. Basically my conditional is shown in the pseudo-code below...

[Code]....

View 2 Replies

Web Forms :: Data From Table Binding To A Listbox?

Nov 22, 2010

I am trying to bind data in a column to a listbox. Here is my code:

[Code]....

Here is my sp:

[Code]....

Am I going about this the right way? Nothing is showing up at all..

View 3 Replies

C# - Dynamically Added ListBox's EventHandler Is Not Firing?

Nov 20, 2010

The scenerio is I have a UserControl. This user control will create dynamically ListBoxes if the given List's count > 0. The controls are adding dynamically, there is no problem with adding them, but the event handler is not adding. If I select an item in first listBox, the secondListBox will be added dynamically, and items will add dynamically too. First listBox appears, but the selectedIndexChanged event handler doesn't work. What can be the problem with my code?

EDIT: I tried to add

li.Attributes.Add("onselectedindexchanged","selectedIndexChanged");

or

li.AutoPostBack = true;

but still not firing...

private List<string> myList = new List<string>() { "Serkan", "Kadir" };
private List<string> mySecondList = new List<string>() { "Istanbul", "Ankara" };
protected void Page_Load(object sender, EventArgs e)
{

[Code]....

View 4 Replies

Web Forms :: How To Set The Value Of Each Listbox Item

May 25, 2010

I've been searching the web and no luck. Can someone tell me how to assign values to my listbbox? I used the ValueMember property but when i have more than 1 item it is only set to one value member instead of each of its own.

[Code]....

View 6 Replies

VS 2008 Why Listview Selecteditem Template Call The "select Query" Method Two Time

Apr 29, 2010

why listview selecteditem templete call the "select qry" method two time..?

i used objectdata source for show selected item templete which use select method of dataaccess leyer..

View 6 Replies

Web Forms :: How To Get Listbox Selected Item

Mar 23, 2011

if any body select listbox then

item=item1

if nobody select list box

item=no

how to do it

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved