|
I want to pass the value of the selected item in a dropdownlist to a label. The dropdownlist is inside a FormView and
the label is outside in the main form. I'm trying to do this by implementing an event handler for the event
OnSelectedIndexChanged.
I cannot get it to work as I get an error:
Object reference not set to an instance of an object w.r.t code: Label1.Text = myDDL.SelectedItem.Value.ToString();
Here's the ASP/HTML
...
<asp:formview>
....
<insertitemtemplate>
....
<asp:dropdownlist id="DropDownList1" runat="server" datasourceid="SqlDataSource1"
datatextfield="StaffID" datavaluefield="StaffID" selectedvalue="<%# Bind("StaffID") %>" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" ondatabound="DropDownList1_DataBound">
....
....
<
<asp:sqldatasource id="SqlDataSource1" runat="server"
connectionstring="<%$ ConnectionStrings:MyConnectionString %>"
selectcommand="SELECT StaffID FROM Staff_tbl">
...
<asp:label id="Label1" runat="server" text="Label">
Here's the event handler (c#)
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList myDropDownList = (DropDownList)FindControl("DropDownList1");
Label1.Text = myDropDownList.SelectedItem.Value.ToString();
}
My FindControl clearly isn't doing what I think it should.
I can get this to work if the dropdownlist is not inside a FormView where there is no need to use FindControl.
E.g.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedItem.Value.ToString();
}
But unfortunately I NEED to have the dropdownlist inside a FormView.
Thanks
Majella
|
|
|
|
|
Your drop down list will be rendered on the client with a name like FormViewName_DropDownList1.
|
|
|
|
|
Thanks - I had omitted to specify the container (FormView1). Was
DropDownList myDropDownList = (DropDownList)FindControl("DropDownList1");
but should have been
DropDownList myDropDownList = (DropDownList)FormView1.FindControl("DropDownList1");
Many thanks
Majella
|
|
|
|
|
How about something like this?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList myDropDownList = (sender as DropDownList);
if (myDropDownList != null)
Label1.Text = myDropDownList.SelectedItem.Value.ToString();
}
|
|
|
|
|
I have just installed the .NET Framework 1.1 on my machine. But the web application I was developing can no longer access the database I have. I keep getting the error.....
System.Data.OleDb.OleDbException: Unspecified error
Now I know it has something or other to do with permissions. And Have been messing around with every option I can find but still it doesn't want to access it.
Another strage thing it is doing, is I have a number of different .jpgs for the different webforms. And because when I upload it to my webhost it doesn't recognise the file path c:\webapplication....etc etc I simply store all the .jpgs in the root folders and just access it by Image1.jpg instead of having a path name. Right now one of my webforms beckground is blank, if I change it to Image4.Jpg it shows up, if I change it back to Image5.jpg it goes blank again, despite both files being in the root folder.
Any help would be appreciated.
|
|
|
|
|
It's ok I found and fixed the problem. For reference the problem was....
In the .NET Framework 1.0, ASP.NET applications use the TEMP folder that is designated by the environment variables to store temporary files. In .NET Framework 1.1, ASP.NET applications use the profile folder for the local ASPNET account to write temporary files. This profile folder is C:\Documents and Settings\ServerName\ASPNET\TEMP. The ASPNET account has permissions to write to this folder.
|
|
|
|
|
Hi all
I already posted something similar but i ll be morz accurate now. I want to download a file from my web server from a remote computer. I heard it might possible to use a hyperlink and then to do a right click + Save As so the user can chose the directory where he wants to save the file. But i don t know how to do that so i ask if someone can help me with my prob.
Thx a lot
|
|
|
|
|
just point the href of your hyperlink to the document on your server's file system.
|
|
|
|
|
thx for your answer m8
|
|
|
|
|
hi all
how can i use multiple configuration file
that is one web config file and some other files with .config extention and also how to refer the keys
thanx in advance
coolsweety
|
|
|
|
|
|
|
hello sir,
thanx,
i used the same code from code project. if i gave the file name directly, then am getting one exception. and if i gave file name in with relative path it wont give any exception but didnt get any value. the code is shown below.
settings.config
appSettings
add key="Setting1" value="This is Setting 1 from ettings.config" add key="Setting2" value="This is Setting 2 from settings.config"
add key="ConnectionString" value="ConnectString from settings.confg"
appSettings
and web.config is
appSettings file="//Settings.config"
appSettings
and in cs file
string ConfigAttributeValue = ConfigurationManager.AppSettings["ConnectionString"];
Response.Write(ConfigAttributeValue);
exception i ma getting is
The root element must match the name of the section referencing the file, 'appSettings' (c:\inetpub\wwwroot\referexternalfiles\secondtestfileext\Settings.config
am using framework2 and vs2005
can u help me to get rid off this problem
coolsweety
-- modified at 0:37 Tuesday 25th April, 2006
|
|
|
|
|
thanx all, it is working.
the mistake wat i made is i had created the second config file with all attributes in configurationsettings, no need of using all setting use only appsettings in second config file
coolsweety
|
|
|
|
|
I am calling API of our own through dot net code to create a pdf file.After 1016 files created during report generation it's stop creating pdf files. I thing it is all because of Memory Leak. How do i force garbage colleter to release memory. I am using gc.collect() after that gc.gettotalmeory(true). How i reduces the cpu utilization it's show 100 %.
Can any one help me ?
Thanks in advance
Mahesh
|
|
|
|
|
I'm guessing the API to which you're referring is your own in-house COM object? If the memory leak is in the COM object, the .NET garbage collection won't help you, as it's not managed code.
|
|
|
|
|
How do i find out memory leak in my code. If it is in API how do i find it?
|
|
|
|
|
|
So I'm using asp.net 2.0 and I'm creating a table and I use the width property
<table width="100%">
But the compiler says I need to use a newer construct.
So where did the width go? Do i only use it in style now?
Whats up with that.
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
What version of (X)HTML are you using?
But yeah style="width: 100%" is nicer. And you should use layers for building the layout.
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
will its 2005 so it xhtml 1.0
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
That really dosen't matter what VS you are using. You can use XHTML 1.1 with 2003 ...
But I must say that is strange becouse attribute width is perfectly valid...
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Goal - is to set focus to the next textbox in a datarepeater.
Problem - I need to perform a calculation server side after the 1st textbox is changed. I can do this but turning the autopostback = "true". However when I autopostback, I need to set the focus to the next control in the row I was working on. Anyone have any ideas?
I use VB
|
|
|
|
|
Hi Friends,
I have a query, how can we access the HTML control from ASP.NET code behind. "FindControl" is throwing error.
Thanks in advance
Sheel Gohe
|
|
|
|
|
Is the element marked with the attribute runat="server" ?
|
|
|
|