|
Hi,
I am having some problem getting the value from the List Box which is the unique id for the name. It goes something like this. I got a table as this one.
tb_user
ID Name
11 John
12 Peter
13 Mike
So in the list box it will show only
Name
John
Peter
Mike
When I click on the button, it suppose to gather all the ID 1,2,3 to store it some where in the database.
I'd tried lstbox.SelectedValue[0] but this would cost it to retrieve '1' instead of '11', the first character of ID.
So my question is how can I retrieve all the IDs in my list box.
Thanks in advance.
J Liang
|
|
|
|
|
Liang,
you will have to store the Id in the list box as well. Try this:
listBox1.DataSource = somedatasource;
listBox1.DataTextField= "Name";
listBox1.DataValueField= "ID"
Now you can ask for listBox1.SelectedValue and you can get the ID for the item which is selected.
Hope that helps.
-- modified at 7:43 Monday 18th June, 2007
|
|
|
|
|
Hi RepliCrux,
Thanks for the reply.
It seems that I could not find DataTextField and DataValueField when I do listBox1.xxx. Did I missed out something?
This is what I am doing to populate the other listbox
ListItemCollection myCollection = new ListItemCollection();
for (int count = 0; count < mySource.Items.Count; count++)
{
if (mySource.Items[count].Selected == true)
{
myCollection.Add(aSource.Items[count]);
}
}
for (int count = 0; count < myCollection.Count; count++)
{
mySource.Items.Remove(myCollection[count]);
myTarget.Items.Add(myCollection[count]);
}
So when I do myTarget.DataTextField, I can't find the .DataTextField
J Liang
|
|
|
|
|
Hi Liang,
If you are using windows forms you will get the properties as:
mySource.DisplayMember = "Name" ;
mySource.ValueMember = "ID";
DataTextField and DataValueField are for web.
If this does not work send me the code where you are populating the listbox.
Cheers,
|
|
|
|
|
Hi RepliCrux,
Actually I got the function code from Mankayarkarasi (http://www.codeproject.com/aspnet/MCEnhancedListBoxControl.asp[^]
It is like this:
private void AddRemoveItem(ListBox aSource, ListBox aTarget)
{
ListItemCollection licCollection;
try
{
licCollection = new ListItemCollection();
for (int intCount = 0; intCount < aSource.Items.Count; intCount++)
{
if (aSource.Items[intCount].Selected == true)
{
licCollection.Add(aSource.Items[intCount]);
}
}
for (int intCount = 0; intCount < licCollection.Count; intCount++)
{
aSource.Items.Remove(licCollection[intCount]);
aTarget.Items.Add(licCollection[intCount]);
}
}
catch (Exception expException)
{
this.jscript.MsgBox(expException.Message);
}
finally
{
licCollection = null;
}
}
Then from the button to populate, I do this:
protected void btnAssignOne_Click(object sender, EventArgs e)
{
//lstFromUser and lstToUser is ListItem from the listbox
this.AddRemoveItem(this.lstFromUser, this.lstToUser);
}
Then when I click another button, it suppose to gather all the IDs from this.lstToUser and that's where it doesn't work for me.
I suspect the ID did transfer to the this.lstToUser. When I do this.lstToUser.SelectedValue.ToString(), I could get the ID but only the first one. I thought of using this.lstToUser.SelectedValue[0].ToString() but it was not the correct way.
J Liang
|
|
|
|
|
Liang,
I think you are using database to retreive the values. In the article you hae mentioned please have a look at the section "Points Of Interest"
The data in the example is created on the fly. you don't want that. If you want the ID of the table you will need to bind that using binding proprty of the ListBox, as I mentioned earlier and mentioned in the article you have mentioned.
Cheers.
|
|
|
|
|
Liang, have a look at the section "Points Of Interest" (the article you are refering). It is mentioned that if you want to connect to the database you will have to use Databinding.
If you want the ID of the Item, you will have to use the way I mentioned earlier. In the section "Points Of Interest", its specified.
Cheers,
|
|
|
|
|
Hi RepliCrux,
Been quite busy lately, only now I remember to put a reply here.
I got it working though, it seems the way the article said, the ID is already in the listbox, so when I pass the item to another listbox, the ID is already there and here is how I capture all the ID.
for (int i = 0; i < this.lstToUser.Items.Count; i++)
{
if (this.lstToUser.Items[i].Selected == false)
{
this.lstToUser.Items[i].Selected = true;
userlist.Add(this.lstToUser.SelectedValue);
this.lstToUser.Items[i].Selected = false;
}
else
{
userlist.Add(this.lstToUser.SelectedValue);
this.lstToUser.Items[i].Selected = false;
}
}
By giving a command to the list box to select one by one every item in the list and add it into the list item by using this.lstToUser.SelectedValue since the value is suppose to be holding the IDs, then I'll deselect it and select the next one.
But before this we need to do
for (int i = 0; i < this.lstToUser.Items.Count; i++)
{
this.lstToUser.Items[i].Selected = false;
}
To deselect everything in the list box before starting to capture the ID.
This might look strange but at least it works for the mean time
J Liang
|
|
|
|
|
i want to open javascript function in codebehind .
but it open on cell_click event.
pls help me urgently.
gayatri
Gayatri
|
|
|
|
|
niki_nilu wrote: i want to open javascript function in codebehind .
What do you mean ? Opening javascript FUNCTION in code behind ?
|
|
|
|
|
my code is
private void Page_Load(object sender, System.EventArgs e)
{
fpAnaAssgn.Attributes.Add("onClick", "window.ShowDialog()");
}
but i want this code in fpAnaAssgn_CellClick
private void fpAnaAssgn_CellClick (object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
Response.Write(" { window.ShowDialog() }");
}
but i is not working.
Gayatri
|
|
|
|
|
did u give the url or pagename
for example,
response.write("{window.showdialog(url,"window")}")
|
|
|
|
|
I tried you code and got error. Then I replaced showdialog with open. and it worked for me. But if you have pop up blocker installed, you need to click holding Ctrl key.
|
|
|
|
|
i didn't understand your code.
pls explain it.
because i am beginner in asp.net
Gayatri
|
|
|
|
|
What I mean is when clicking hold control key and click.
|
|
|
|
|
Hi guys
I have a usercontrol on my page and I want to refresh that Usercontrol. When any postback event is fired from the PAGE....
Any idea...
|
|
|
|
|
wEb GuRu... wrote: I want to refresh that Usercontrol. When any postback event is fired from the PAGE....
I think it will reload automatically
|
|
|
|
|
Thanks for ur time Navaneeth.
Actualy I want to refresh usercontrol for certain postback events(NOT FOR EVRY POSTBACK)...
Any idea abt tht???
|
|
|
|
|
Could you tell me the scenario where you will use this ?
|
|
|
|
|
Well I have a UserControl containing "Unsold Ads of a customer" in a label. I have used this control through out the customer account area.
Now when customer mark an Ad as "Sold"(from Datagrid in page) then label displaying Unsold Ads should be refreshed to show only unsold ads.
|
|
|
|
|
If Customer keeps browser idle also do you want to change it ? If so you can make use of some AJAX concepts. If customer refreshes the page , I think your left menu also will update.
|
|
|
|
|
Hello to everyone,
i'm trying to compare the value entered in the text box (Current Password field ) by the user to the valuse given in databse.
initially i did by makin another textbox which is not visible in the page and then used compare validator to compare the given value against original value...
Can any body suggest me any simple method..
|
|
|
|
|
hemant_garg wrote: initially i did by makin another textbox which is not visible in the page and then used compare validator to compare the given value against original value...
This is not a good method. A person who is viewing the source can easily get the value stored in hidden field. I suggest you to do this in server side rather than going for validators. Connect to db and check the password is correct. If not display a message. Don't allow user to complete the process untill both passwords are same
|
|
|
|
|
|
hello hemant,
just try to use the data reader and try to fetch the values from the database then compare the
values like
if (textbox1.text = dr("BLAHBLAH") then
msgbox("Equal")
end if
regards,
koolprasad2003
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|