|
When page is initially loaded, all controls are displayed properly. However, on postback, some controls are missed and appear blank (odd, as they have initial text, and the db.GetText method returns either valid text or ctrl.UniqueID surrounded by underscores).
|
|
|
|
|
I need to fill a dropdownlist with 1 to 60. So I did it by doing the following code:
for(int i=0; i <=60; i++)
DropdownList1.Items.Add(new ListItem(i.ToString(), i.ToString()))
However, I was thinking this probally is not good idea to use "new ListItem" each time. So I replace the above with the following:
ListItem li = new ListItem();
for(int i=0; i <=60; i++)
{
li.Text = i.ToString();
li.Value = i.ToString();
DropdownList1.Items.Add(li)
}
But the result turned to be all the items in the list are 60. Is there anything in the second code wrong? I have seen people using the first code all the time, but bot the second code. Does anybody know why? Could anybody give me some ideas why the second code doesn't work?
What's the life cycle of the new item when using
DropdownList1.Items.Add(new ListItem(i.ToString(), i.ToString()))
The last IMPORTANT question is: Does using "new listitem" will cause performance issue, such as more memory allocation, etc?
I would really appreciate any ideas!
Thank you in advance!
|
|
|
|
|
In the second code you add the SAME list item 60 times. Now if you change the items text and value you change ALL items.
Everytime you add that listitem to the dropdownlist you add a REFERENCE and NOT a COPY to the list. You could, for example, add that listitem to another dropdownlist without any problems. And changing it would change the value in both dropdownlists.
I hope i could help you.
If not just say it
|
|
|
|
|
Thanks for your respones.
It looks like the first approach is the only way to programmatically adding item to asp:dropdownlist.
|
|
|
|
|
vicky457 wrote: The last IMPORTANT question is: Does using "new listitem" will cause performance issue, such as more memory allocation, etc?
Yes, it means you end up with 60 items, which is what you want. Otherwise, you have one item, which you keep changing the value of.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello all,
I've been searching all day for an article or tutorial on how to get data from a SQL Server 2000 database and export the data to excel 2003 so that multiple worksheets are created, and information is displayed in these worksheets. Data will be coming from multiple tables, and I'm using C# and asp.net 2.0. User will click on an asp.net button to pull the data and put it in an excel spreadsheet.
Thanks
|
|
|
|
|
I am trying out VS 2005 for the first time.
Didn't really like the website project, and installed the update for 'Web Application Project' to try it out.
But I am NOT able to view the Web Application Project in the project types when I try to create a new project?
Any help, what could I be missing?
Thanks in advance,
atul
|
|
|
|
|
Did you reboot?
Wep application project appears under the C# templates when I create a new project.
|
|
|
|
|
Hey,
Thanks for the reply.
Its really embarrassing for me to admit but I had not installed a pre-requisite!!!
Its working now for me.
On a side note, do you know why there isn't a namespace for the code behind when I create a new web page in WebSite project in .NET 2.0 ?
(its there for web app project)
Thanks,
Atul
|
|
|
|
|
Can anyone recommend a tutorial for GridViews ?
Specifically I want to highlight a row when the cursor hover over it. And I want to be able to select a row by clicking anywhere on it.
|
|
|
|
|
|
Thanks for your help - Digsy
|
|
|
|
|
|
Hi,
i'm using and i need to refer to a treeview control from another .aspx , any help would be appreciated..
Thanks
|
|
|
|
|
in the frameset drag ur aspx page....and ur problem is solved..
|
|
|
|
|
Heya guys and girls,
I am writing a CMS page for a quiz and want to use the new GridView control along with an in memory data store as a datasource.
Here is is how I would like it to work.
The user logs onto the CMS quiz page to add or edit a quiz. The quiz can contain any number of questions and answers and once the user has added a title for the quiz and as many questions / answers as they want they then move on to the next page to preview / confirm results.
The problem with using a GridView in the classic way would be that I would set it up with a SQLDataSource. this however would mean when I updated or added a row then the database would imedietly be updated. I need a way of storing an off line represention of the data and only applying the changes if the user confirms the preview of the data on the next page.
I have tried using a DataTable but I get told it does not implement IDataSource. I also need to GridView to handle a sitation where there is no data and we only need to add rows (in the case of adding a quiz).
Has anyone come across this problem before?
Cheers
Steve
"Gödel proved that any formal system that defines the primitive recursive functions must be either incomplete or inconsistent. In particular one could not prove from within the system that the system itself was consistent even though the question could be formulated within the system."
|
|
|
|
|
You can use a dataTable and persist the datatable in viewState or Session state. You can also use a blank table and add a new row to the dataTable easily enough. As for the IDataSource, I don't know what that is.
|
|
|
|
|
I have 2 Forms
1. Display Employee Details( Like Employee Id, Name etc) in DataGrid.
2. Employee Edit Form.
When I click Edit Image on DataGrid, I passe the Employee Id using javascript code to the Popup window(Edit Employee Details) and Received all details . I done some Change and click Update botton. It's Update the details in database.
I want when I click update botton. The popwindow should close and Refresh the Datagrid on Previous Page(Display Employee Details)
I'm Using .NET2003 and VB.NET Backend code
Mohan Balal
|
|
|
|
|
Dear I'll suggest you to use multiview and view controls and use show hide tricks. make your life easy.
Multiview1.activeindex=0 or Multiview1.activeindex=1 or so on
For closing window you need to use javascript window.close() i guess. and when you are closing your window redirect user to your employee detail page using response.redirect(url). as you have to reconnect to database to fill the values into a grid. this is what i guess.
|
|
|
|
|
Thanks for your Kind suggestin
Any other Good way to some this problem
Mohan balal
|
|
|
|
|
I think this[^] article will give you a fair idea how to refresh the parent page from a pop up page.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi All
I have added a NewItem (SQL Database)in my Project where I added some table.
Now I would like to run some query, how can I connect with the database or whta will be the
Dim _Con as SqlConnection = New SqlConnection( ; ; )
Thans
Sarfarj Ahmed
|
|
|
|
|
Check
www.connectionstrings.com
Naveed Kamboh
Complexity kills, Write easy code for your self.
isolutionteam
|
|
|
|
|
is it possible to have a link/button/etc that when clicked creates a CVS from a dataset (that bit i can do) then presents it as a download without having to write the file to the server?
So basicly when they click the link/button it streams the data from the dataset into a text file that is being downloaded.
Thanks
|
|
|
|
|
Yes it is possible dear
follwoing code may be help full
//HTMl Document
public void Create_HTML_Document(string strBody,string filename)
{
try
{
string header = "<title>News letter";
header += strBody;
header += "";
header += "";
StreamWriter sw = File.CreateText(Server.MapPath("../NewsLetters/") + filename +".txt");
sw.Write(header);
sw.Close();
}
catch (Exception)
{
}
}
Naveed Kamboh
Complexity kills, Write easy code for your self.
isolutionteam
|
|
|
|