|
Go on, fill your boots[^].
yadlaprasad wrote: its a bit urgent fr me
It's always urgent. Every tedious post. Urgent. Listen matey, this may be the thing that's keeping you up on a night, but I can't really bring myself to give a flying fart about it. You come in here without doing any research, spew your text speak all over the place and then want us to do your thinking for you. No, I say, no. Learn to do some research for yourself. Google should be your first port of call.
|
|
|
|
|
Sometime within the last week some code broke which I'm pretty sure hasn't changed. It's a simple DropDownList bound to a Country table in the database.
The data in the table hasn't changed. The code for that page hasn't changed. The web.config hasn't changed. And all the other pages which talk to the DB work. If I checkout the codebase and get it running on my home system it works including the DropDownList with countries.
here's the offending code snippet
<br />
IDataReader dr = DB.GetRS("select * from Country " + DB.GetNoLock() + " where Published = 1 order by DisplayOrder,Name");<br />
BillingCountry.DataSource = dr;<br />
BillingCountry.DataTextField = "Name";<br />
BillingCountry.DataValueField = "Name";<br />
BillingCountry.DataBind();<br />
dr.Close();<br />
BillingCountry.SelectedIndex = 0;<br />
the simple markup
<br />
<asp:DropDownList ID="BillingCountry" runat="server" OnSelectedIndexChanged="BillingCountry_OnChange" AutoPostBack="True"></asp:DropDownList><br />
the query implementation
<br />
static public IDataReader GetRS(String Sql)<br />
{<br />
SqlConnection dbconn = new SqlConnection();<br />
dbconn.ConnectionString = DB.GetDBConn();<br />
dbconn.Open();<br />
SqlCommand cmd = new SqlCommand(Sql, dbconn);<br />
return cmd.ExecuteReader(CommandBehavior.CloseConnection);<br />
}<br />
and the error it produces
<br />
'BillingCountry' has a SelectedValue which is invalid because it does not exist in the list of items.<br />
Parameter name: value <br />
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br />
<br />
Exception Details: System.ArgumentOutOfRangeException: 'BillingCountry' has a SelectedValue which is invalid because it does not exist in the list of items.<br />
Parameter name: value<br />
<br />
Source Error: <br />
Line 442: BillingCountry.DataTextField = "Name";<br />
Line 443: BillingCountry.DataValueField = "Name";<br />
Line 444: BillingCountry.DataBind();<br />
Line 445: dr.Close();<br />
Line 446: BillingCountry.SelectedIndex = 0;<br />
It's throwing the exception on the call to DataBind().
The odd part is that it says the SelectedValue doesn't exist in the list of items yet its looking for the item "United States" which it got from the database! Here's a SS of the results returned by the above query country.jpg[^].
At this point I assume its some DB related component on my system that's gone bad but I'm not too familiar with the inner workings enough to know what to look into. Any suggestions on what to look at / reinstall / uninstall? Have any of the recent MS updates affected the components involved here?
Todd Smith
|
|
|
|
|
http://www.west-wind.com/weblog/posts/2068.aspx[^]
After hours of searching I finally landed upon this thread. I fixed bug by setting SelectedValue = null before the call to DataBind.
<br />
IDataReader dr = DB.GetRS("select * from Country " + DB.GetNoLock() + " where Published = 1 order by DisplayOrder,Name");<br />
BillingCountry.SelectedValue = null;<br />
BillingCountry.DataSource = dr;<br />
BillingCountry.DataTextField = "Name";<br />
BillingCountry.DataValueField = "Name";<br />
BillingCountry.DataBind();<br />
dr.Close();<br />
BillingCountry.SelectedIndex = 0;<br />
Not sure what changed which caused this to start happening all of the sudden but at least it works now.
I especially like this reply to the above thread:
This error is VERY confusing.. my code works fine on one server, but not on another???
Todd Smith
|
|
|
|
|
I got this exception once a day on my website, and subsequent visit to the web site is fine. I debugged through my code and the connection state is always 'Closed' on any connection even when there is no problem. I guess Enterprise library is handling connection automatically, but why do I get this exception once a day? I am using .NET2.0, Sql2000 and Enterprise library (2.0)
Here's the code:
public static DataTable GetDataTable(string procName) {
DataSet dataSet = new DataSet();
try {
Database database = DatabaseFactory.CreateDatabase("myProject");
//use GetSqlStringCommand so that it accepts sp with parameter
command = database.GetSqlStringCommand(procName);
dataSet = database.ExecuteDataSet(command);
}
catch(Exception exception) {
Utilities.ProcessException(exception, procName);
}
return dataSet.Tables[0];
}
And here's the exception:
Message:Invalid operation. The connection is closed.
Source:System.Data
Method:System.Data.SqlClient.SqlInternalConnection GetOpenConnection()
Stack Trace: at System.Data.SqlClient.SqlConnection.GetOpenConnection()
at System.Data.SqlClient.SqlConnection.get_Parser()
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoLoadDataSet(DbCommand command, DataSet dataSet, String[] tableNames)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet(DbCommand command, DataSet dataSet, String[] tableNames)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet(DbCommand command, DataSet dataSet, String tableName)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteDataSet(DbCommand command)
at DataAccess.GetDataTable(String procName) in d:\Inetpub\www\wwwroot\data\App_Code\DataAccess.cs:line 81
|
|
|
|
|
Without having a look at the rest of your code we can only make educated guesses, but have you checked to see if the connections have been closed and disposed?
|
|
|
|
|
Thanks for the reply, Pete.
My application uses ApplicationBlock code which takes care of connection open or close. I stepped into the ApplicationBlock code, just like the trace printed out during the exception, it goes to the DoLoadDataSet function. Here's snippet from that function
private void DoLoadDataSet(DbCommand command, DataSet dataSet, string[] tableNames)
{
using (DbDataAdapter adapter = GetDataAdapter(UpdateBehavior.Standard))
{
((IDbDataAdapter)adapter).SelectCommand = command;
adapter.Fill(dataSet);
}
}
Before and after adapter.Fill, the connection is always closed. Also, based on the stack trace, Enterprise library opens connection, fills dataset and close connection immediately. This is what I want, and it is working most of the day, except 1 exception a day.
|
|
|
|
|
I have created a simpe web control for geting rss news from bbc. this method I have is:
private DataTable GetRssDataFeed()
{
DataTable RssTable = new DataTable("RssTable");
DataColumn dtCol;
DataRow dtRow;
// Create Title column and add to the DataTable.
dtCol = new DataColumn();
dtCol.DataType = System.Type.GetType("System.String");
dtCol.ColumnName = "Title";
dtCol.Caption = "Title";
// Add the column to the DataColumnCollection.
RssTable.Columns.Add(dtCol);
// Create Description and add to the DataTable.
dtCol = new DataColumn();
dtCol.DataType = System.Type.GetType("System.String");
dtCol.ColumnName = "Description";
dtCol.Caption = "Description";
// Add the column to the DataColumnCollection.
RssTable.Columns.Add(dtCol);
// Create Link and add to the DataTable.
dtCol = new DataColumn();
dtCol.DataType = System.Type.GetType("System.String");
dtCol.ColumnName = "Link";
dtCol.Caption = "Link";
// Add the column to the DataColumnCollection.
RssTable.Columns.Add(dtCol);
// Create Title Description and add to the DataTable.
dtCol = new DataColumn();
dtCol.DataType = System.Type.GetType("System.String");
dtCol.ColumnName = "Publication Date /Time";
dtCol.Caption = "Publication Date / Time";
// Add the column to the DataColumnCollection.
RssTable.Columns.Add(dtCol);
// Create a new XmlTextReader from the specified URL (RSS feed)
rssReader = new XmlTextReader(rssUrl);
rssDoc = new XmlDocument();
// Load the XML content into a XmlDocument
rssDoc.Load(rssReader);
// Loop for the <rss> tag
for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
{
// If it is the rss tag
if (rssDoc.ChildNodes[i].Name == "rss")
{
// <rss> tag found
nodeRss = rssDoc.ChildNodes[i];
}
}
// Loop for the <channel> tag
for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
{
// If it is the channel tag
if (nodeRss.ChildNodes[i].Name == "channel")
{
// <channel> tag found
nodeChannel = nodeRss.ChildNodes[i];
}
}
// Loop for the <title>, <link>, <description> and all the other tags
for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
{
// If it is the item tag, then it has children tags which we will add as items to the DataGrid1
if (nodeChannel.ChildNodes[i].Name == "item")
{
nodeItem = nodeChannel.ChildNodes[i];
// Create a new row in the datagrid containing information from inside the nodes
dtRow = RssTable.NewRow();
dtRow["Title"] = nodeItem["title"].InnerText;
dtRow["Description"] = nodeItem["description"].InnerText;
dtRow["Link"] = nodeItem["link"].InnerText;
dtRow["Publication Date /Time"] = nodeItem["pubDate"].InnerText;
RssTable.Rows.Add(dtRow);
}
}
return RssTable;
}
...
in my on PageLoad:
protected void Page_Load(object sender, EventArgs e)
{
//this.txtResults.Text = GetRssDataFeed();
DataTable A = GetRssDataFeed();
this.DataGrid1.DataSource = A;
this.DataGrid1.DataBind();
}
When I run this, I see nothing, now datagrid control, no data, and I just cant seem to work out why this does not work. If I use the debugger, I can see that it does get the data!!!! Just a little confused here! </description></link>
My bad! It seems i did not set the width property correctly!
modified on Thursday, January 10, 2008 3:56:43 PM
|
|
|
|
|
Through my asp net web application i need to be able to add tasks and meeting information to my calendar in outlook 2003. I am unable to do so using the normal outlook api. I read that in some sites that i wont be able to use the APIs through ASP.net whereas the same code works fine when its a console application. Are there any other alternatives that help me achieve the same??
|
|
|
|
|
i am using vs2005 to develop a web application, however the stylesheets do not load when i open it in vs but loads fine when i use dream weaver or when i run the application. does anyone know y???
many thanks
|
|
|
|
|
I am trying to use the gridview control to display data on page, however the data is not displayed. I am not getting any build error but its just not displaying the data. Any ideas??
<asp:gridview id="GridView1" runat="server" ><br="" mode="hold"> <asp:accessdatasource id="AccessDataSource1" runat="server" datafile="~/glaxodata.mdb">
SelectCommand="SELECT [ID], [OrderCode] FROM [glaxoAll5032007OrderDetail]">
Can anyone spot what i may have done wrong???
Many Thanks in advance.
|
|
|
|
|
You need to set DataSourceID on the GridView:
<asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1"></asp:GridView>
|
|
|
|
|
Many thanks!! that worked.
|
|
|
|
|
Hey friends.
I want to create image from html string.
I tried alots but I did not get any solution yet.
Can any body know how to create image from html string.
Thanks in advance
please don't forget to vote on the post that helped you.
|
|
|
|
|
Imran Khan Pathan wrote: I want to create image from html string.
I am not getting what you are trying to do. How you can create image from a HTML string ?
|
|
|
|
|
N a v a n e e t h wrote: I am not getting what you are trying to do. How you can create image from a HTML string ?
Graphics has DrawString method to draw image from string.
But in my case I have string in html format.
You can better understand by this Link
I am working on image editor.In this page I need to put one Button to view image.So I want to create Image from innerHTML of main div Tag.
Please visit above link.
please don't forget to vote on the post that helped you.
|
|
|
|
|
I don't think that DrawString() can parse HTML tags and draw the output. If you just want to draw plain text, remove HTML tags and draw. If you want rendered output of that HTML, then you need to use other GDI methods to create that and draw it.
|
|
|
|
|
Hey.Thanks for replay.
I have done it using Winnovative dll.
Thanks again
please don't forget to vote on the post that helped you.
|
|
|
|
|
Hi
I am using a GirdView under one colume is hyperlink. I want that when i click the hyperlink then display msgbox. "Do you want to Open the --- page" Yes Or No. if Yes then goto another page.
Please help me.
|
|
|
|
|
Here is a simple piece of javascript which prompts before redirecting:
<script type="text/javascript">
function go(pageTitle, pageUrl){
if (confirm("Do you want to Open the " + pageTitle + " page?")) {
window.location = pageUrl;
}
}
</script>
<a href="javascript:go('Cool', 'cool.aspx');">Go to New Page</a>
You should be able to integrate this into your GridView hyperlinks.
|
|
|
|
|
This function is take a two argument OK or Cancel but i want YES or NO
|
|
|
|
|
The confirm box is part of the browser so you have limited control over it from javascript.
If your know that your target audience is exclusively IE then you can check out this solution[^].
For a more browser independent approach you can implement your own popup, here is an example[^].
The disadvantage with this approach is that popup blockers will block it.
You can also use the ModalPopup[^] control which is part of the ASP.NET AJAX framework.
|
|
|
|
|
what is the maximum character length of an hidden field it can take
|
|
|
|
|
A normal HTML input text can hold 2147483647 values. So I guess hidden field can also hold that
|
|
|
|
|
Hello All
i have an asp.net page.i have saved all the page data in a text file like
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTE5MDA2OTYyMQ9kFgI
CAw9kFhICAw8PFgIeBFRleHRlZGQCBw8PFgIfAAUJMS8xMC8yMDA4ZGQCCw8PFgIfAAUFTm9v
MTFkZAIPDxBkEBU...
now i want to display this data (__VIEWSTATE) when the page run for the 2nd time.
Actually my requirement is user will save the data.when 2nd time user will come to that page user will see his previous saved data.
plz help me in this regards.
thanks in advance.
Sujit
|
|
|
|
|
Sujit Mandal. wrote: have an asp.net page.i have saved all the page data in a text file like
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTE5MDA2OTYyMQ9kFgI
CAw9kFhICAw8PFgIeBFRleHRlZGQCBw8PFgIfAAUJMS8xMC8yMDA4ZGQCCw8PFgIfAAUFTm9v
MTFkZAIPDxBkEBU...
now i want to display this data (__VIEWSTATE) when the page run for the 2nd time.
Actually my requirement is user will save the data.when 2nd time user will come to that page user will see his previous saved data.
You can't load viewstate data from a string. If you want to show it again when user visits, store the values in database/session, and reload it.
|
|
|
|