|
Hi,
When you refresh your page the last executed event in the aspx page gets executed again. Thats why one more controls is added.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Whilst the other two answers are technically correct I thought I'd elaborate:
When you click the button it causes a POST request to the server and returns a page. When you refresh the page it re-submits the POST request which contains the event information to perform, causing it to add another control. I'm not sure what you can do about it, why is this a problem anyway?
|
|
|
|
|
I'm sorry, i didn't find your problem all that refreshing...
|
|
|
|
|
Hi ,
I am adding dynamic controls on form on button click....everything working fine....but if I click on button and refresh the page one more control get added.
Thanks.
Nagraj
|
|
|
|
|
Hi All,
Please let me know if there is any way to select multiple items from a dropdown list.
The requirement is as follows:
i have a drop down list which is populated from the database.The user should be able to select multiple items from the list and press the submit button.On submitting, all the selected items from the list should be populated in a single column of a row in a table.
Kindly send me the code.
Thank You.
|
|
|
|
|
rameshbhojan wrote: i have a drop down list which is populated from the database.The user should be able to select multiple items from the list
I think not possible. Try using listbox, checkedlistbox.
|
|
|
|
|
ok navaneeth,
even if i use list box,how do i make multiple entries into the single column of a row in a table
|
|
|
|
|
How about separating the values with comma or some other separator. At the time of retrieving data, split value using the separator.
|
|
|
|
|
navaneeth,
i am new to .Net and i don get you exactly.......
could you please send the code and query for wat u suggested
|
|
|
|
|
Assume that you put a list box. use the following method to form the string to be inserted to DB
string strInsertValue = string.Empty;
for(int i=0;i<=ListBoxCount-1;i++)
{
IfListItemSelected
strInsertValue = ListBoxSelectedValue + ",";
}
at the time of retrieving data from DB split the data with ','. You will get a string array and do the processing with that.
|
|
|
|
|
navaneeth i don find any keyword like IfListItemSelected
which was in the code you sent
|
|
|
|
|
I think that navaneeth's reply is to put all the items in a single row of a column, not what you were looking for.
Where do you get a problem with several inserts depending on the data selected? You just need some kind of loop.
|
|
|
|
|
Paddy Boyd wrote: I think that navaneeth's reply is to put all the items in a single row of a column
That is his requirement. See his previous posting
|
|
|
|
|
His requirement was for single column of a row, not the other way around. Of course i may be misreading what he actually wants...
|
|
|
|
|
|
paddy i guess tats wat i want.......
let me explain.....
the requirement is once the user selects multiple items from the list box,
and submits the form, all the selected values should be inserted into a particular column of the table i,e suppose the listbox has a list if languages say, then all the selected languages from the listbox, should be inserted into the column called "languages", (seperated by comma) of a row in the table.
do you have a solution for this???
|
|
|
|
|
Hi,
The following is the code you can use to get comma separated string of selected Items from the listbox.
string strSelected = "";
foreach ( ListItem lstItem in lstBox.Items )
{
if ( lstItem.Selected )
{
strSelected += lstItem.Value + ",";
}
}
put "strSelected" in to your insert query and you are done.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hi Chetan,
Thanks yaar for the code...
its working fine now!!!
|
|
|
|
|
hey Chetan,
wat should i set to ensure that a maximum of only 3 items could be selected from a list box???
is there any property for that or some other code???
please send me the details
|
|
|
|
|
Hi,
There is no such property which you can set get your required functionality.
But you can apply your logic in code behind or in javascript to check how many items are selected.
In code behind you can use GetSelectedIndices() of listbox which will return an array of all the indices of selected items in the listbox.
you can check for the length of that array if it is less than 3.
int[] selectedindices = lstBox.GetSelectedIndices();
string strSelected = "";
if(selectedindices.Length<=3)
{
foreach(int i in selectedindices)
{
strSelected += lstBox.Items[i].Value + ",";
}
}
use strSelected in the Insert query.
I hope this will help you.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hey Chetan ,
thrz one more issue.......
as soon as i select one item from the list box, the page gets refreshed and the control goes back to the top of the page, then again i ve to scroll down to the list box and select the next item...... how do i handle this???
actually in the listbix properties i ve set auto post back as "true".does this cause any issues?
|
|
|
|
|
Hi,
The AutoPostBack property of your listbox should be set to false if you dont want any server code to be executed when u select an item from the listbox.
So set AutoPostBack property to false for your listbox and it is done.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hi Chetan,
I have another requirement.
I need the code for uploading files into the database.
I tried using the FileUpload control in ASP.NET 2.0, and got the code(to be put in the button click event code) to upload the files in my own system in some other location.
However, my requirement is that i should be able to upload the file into a remote system or the SQL database.
Please give me the code for this....
Thank You.
|
|
|
|
|
i tried the following code for upload into mu own system but i don know how to go about and upload in the remote server.Please Help.
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try
{
//The following line of code specifies the path
FileUpload1.SaveAs("D:\\Uploads\\" +
Label1.Text = "The file has been successfully uploaded in to: " +
"D:\\Uploads\\" + FileUpload1.FileName;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "Oops! You forgot to specify the file! Browse for the file above.";
}
}
|
|
|
|
|
Hi,
You just need to provide the server path to the SaveAs Function
FileUpload1.SaveAs("http:\\servername\\foldername\\" + filename;
where filename is the name of file you want to upload.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|