Web Forms :: Null Datasource On Page_Load

Apr 20, 2010

I've been trying solution I've found oline all day trying to get a GridView to Display its Header when its datasource returns 0 rows. So far, nothing has worked for me. I did come across an interesting bit of code, but I'm having a spot of bother with something else preventing me from getting it to work.

[Code]....

View 4 Replies


Similar Messages:

C# - ViewState Is NULL In Page_Load But Not Postback?

Jun 4, 2010

I've got a weird problem with a NullReferenceException on a high traffic website my company hosts. The exceptions are logged with full stack-traces but I am unable to reproduce it.The exception occurs a couple of times a day, for different users, and it's a NullReferenceException thrown in the code block below:

protected void Page_Load(object sender, EventArgs e)
{
...

if (!Page.IsPostBack)
{
...
this.ViewState[StaticClass.StaticStringProperty] = StaticClass.StaticIntProperty; // this is the line the exception occurs on
...
}
}

The only place I can figure that a NullReferenceException would be thrown is if ViewState is NULL, but I've never known that and can't find any reason why this would be the case in a Page_Load that isn't a postback.StaticStringProperty and StaticIntProperty are both initialised, static properties of StaticClass.

StaticStringProperty is defined as:

public const string StaticStringProperty = "IdFromClient";

Does anyone know how this could happen, or any other reason why a NullReferenceException would be thrown on the above line?

EDIT.As requested, the full stack-trace for the error is as follows. Line 54 is the line I've highlighted above.

at MyCompany.MyApplication.Appliance.Page_Load(Object sender, EventArgs e) in C:Documents and SettingsshellamaMy DocumentsMyApplicationAppliance.aspx.cs:line 54
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)[code]....

View 1 Replies

State Management :: Read Session["key"] On Page_Load Of AnotherPage.aspx But It's Null - What Can Cause This

May 20, 2010

I'm doing nothing special with session...

I just put some value on button_click event handler and then redirect to another page

like this { Session["key"]="value"; Responde.Redirect("AnotherPage.aspx"); }

And then I try to read Session["key"] on Page_Load of AnotherPage.aspx but it's null!

What can cause this?

P.S. When I use Server.Transfer() instead of Response.Redirect() it works fine.

View 2 Replies

DataSource Controls :: Refer To Fields In ObjectDataSource During Page_Load?

Jan 5, 2010

At first, I had my datalist being populated by my class 'PM' - I did it all inside the Page_Load event. Since there was a dataset being returned, I could assign different variables to fields in the Datatable, like:

[Code]....

Now, for reasons I won't go into here, I'm changing to an ObjectDataSource, using the same method to do the 'Select' of data... How can I do the same variable assigning, with the ObjectDataSource?

View 4 Replies

DataSource Controls :: Use Is Null In Query Without Using Parameters For It Or Should Use Parameters For This Field Where Value Is NULL

Jan 21, 2010

here is my code for selectiong some records from db table

string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];

here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this

View 8 Replies

DataSource Controls :: Null Datasource - Forward To New Page

Jan 19, 2010

I have page that has a datasource. The datasource executes a stored procedure and returns results. If the result is NULL, I'd like to forward the user to an error page. How would I accomplish this with ASP.NET and C#?

View 1 Replies

Forms Data Controls :: Value Of Datasource Of Checkboxlist Is Becoming Null

Sep 9, 2010

Page 1: To add a record in to DB. At this page, as per the user requests , few controls will be added to the page from server side code. one of them is checkbox list. and when user is requesting to save data, its going to the DB. Everything is fine upto now.

Page 2: To edit the record which is entered from page no 1. When user requests to edit the record entered at page no 1, i'm redirecting user to this update page, with record id, and generating the required controls to show the values. Now the main problem is :

When page is loading first time, I m creating the required controls and then assigning the values to them to edit. but after that at each postback, the value of datasource of checkboxlist is becoming null, same case is with the label control. but the value of textbox is same, it is not becoming empty at each postback. In code: In code i have created two method to generate controls.

1st is : to create new controls, and to assign values to them

2nd is : to regenerate the controls at each postback, with the same IDs, but not assigning any value here.

I think viewstate will reload the values of respective controls, if IDs are same.

View 4 Replies

Forms Data Controls :: Gridview Datasource Is Null In Postback?

May 10, 2010

In asp I want to add row to my gridview when I read barcode. But when I want to add second row , gridview.datasource = null. So, my first row is removed from gridview in TxtBxBarcode_TextChanged event.

TxtBxBarcode and gridview are in the different update panels.

How can I prevent this "gridview.datasource is null when Postback" ?

View 4 Replies

Forms Data Controls :: Gridview Datasource Null When Sorting

Jan 11, 2010

I have 4 gridviews on a page that get databound with a datatable from sql. So I have created the sort/paging events for each. These were working fine. However now they do not work.

[Code]....

HTML Declaration:

[Code]....

View 3 Replies

C# - When Does A Gridview Have A Null DataSource

Dec 1, 2010

I've read multiple sources that say Gridview's do not persist the Gridview.DataSource property on postback. My understanding is that in term's of ASP.NET, a postback is any page load that is not the first pageload (see MSDN). I've got a situation with 2 very similar gridviews.

GvOne.DataSource is null on postback.
GvTwo.DataSource is NOT null on postback.

The only big difference outside of a few differing columns is GvOne is populated with the Entity Framework and LINQ. GvTwo is populated by a DataTable filled by a SqlDataAdapter. Further, GvOne and GvTwo have a TemplateField with a TextBox that I use to gather user input. Both use the same code to pull the TextBox.Text on postback:

TextBox tb = (TextBox)GvOne.Rows[i].FindControl("actualTxt");
GvOne properly gathers tb.Text. GvTwo always finds the tb.Text value to be 0.
Basic Gridview code:
<asp:GridView ID="GvOne" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Return">
<ItemTemplate>
<asp:TextBox id="actualTxt" runat="server" Text='0' Width="40px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
...
</Columns>
</asp:GridView>
<asp:GridView ID="GvTwo" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Order">
<ItemTemplate>
<asp:TextBox id="actualTxt" runat="server" Text='0' Width="40px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
...
</Columns>
</asp:GridView>

Changing GvTwo to use Entity Framework and LINQ is a potential solution, albeit a major undertaking. Does anyone know what is going on here? UPDATE (See my comment on Joel Etherton's Answer) Due to popular demand here is the code to populate the gridview within Page_Load event for GvTwo (GvOne is similar):

ordersGV.DataSource = dataSetObject.Tables["activeParts"];
ordersGV.DataBind();

Searching through the code behind I found no other references to ordersGv.Datasource and no other events that are hooked into associated with the page life cycle.

View 2 Replies

Datasource Going To Null In Gridview

Jan 27, 2011

I have a gridview that I bind with the result of a linq query that's in a list. In my code behind, I then bind the gridview with the list

MyGrid.DataSource = MyList;
MyGrid.DataBind();

I also have the grid with sorting enabled:

<asp: GridView..... ID="MyGrid" AllowSorting = "True" OnSorting = "SortMyGrid">

In the code behind, I have the event handler set up like this:

protected void MyGrid(object sender, GridViewSortEventArgs e)
{
var NewDataSource = from d in MyList
orderby e.SortExpression
select d;
}

Now the problem is that MyList is null when the event handler takes over! I'm tracing it and I see it loaded fine, I see the gridview on the page with the correct data but as soon as I click a column header to sort the grid, the MyList goes to null! Why?

View 2 Replies

DataSource Controls :: How To Add An Sqlparameter With Value Of Null

Apr 17, 2010

If Request.QueryString("departmentId").ToString() = "0" Then
SqlDataSource1.SelectParameters.Add("departmentId", TypeCode.Int32, 0.ToString())

I want to add a null value instead of 0.string() for the sqlparameter departmentId how do I do this?

View 3 Replies

DataSource Controls :: How To Handle Null Value Between Sql And C#

Feb 3, 2010

I need to retrive a value from a column of a table per stored proc. This is usually an integer, but also can be null. I get this value and store it in a session variable.

Later, I need to pass this same session variable to another stored proc.

Session["myVariable"] = ds.tables[0].rows[0][1]; // this can be null or an integer

somewhere else in the project, I need to pass it to another stored proc exactly as received.

[code]....

View 4 Replies

Forms Data Controls :: Displaying A Null Or Empty Cell For A Null Datetime Database Value In Gridview?

Dec 6, 2010

I have setup my business object to have a create_date and edit_date members both datetime datatypes. My company want to display the create_date and edit_date fields in a gridview for each transaction. The problem i have is that after insterting a record it will have a valid create_date but no edit_date and when displayed in the gridview it defaults to datetime.minvalue (My default). How on earth do i show an empty field in my gridview for a null datetime field in the database?

I am using similar architecture to the Imar Spaanjaars example of a tiered solution. With a few small tweeks it has worked well for me for ages. I am passing a List<Database> to my object datasource which connects to my gridview.

View 3 Replies

DataSource Controls :: Update Syntax With Null?

Jan 9, 2010

here is my update query syntax.my problem is.if i update only logo1 and logo3 with null logo2 and img null then my query should be update the other record.just dont update null value record but other should be update.but below my query can not update any record.

UPDATE tbitem set itemname= @itemname,note=@note,
price=@price,qty=@qty,logo1=@logo1,
logo2=@logo2,logo3=@logo3,img=@img
where id =@id
and @logo1 is
null and @logo2
is null
and @logo3
is null
and @img is
null

View 1 Replies

DataSource Controls :: Identify Row Of A Column Contains Null Value

Apr 9, 2010

having a table with column having null values

how to identify row of a column contains null value?

i tried isnull,nullif properties but such functions im getting emptied rows

View 4 Replies

DataSource Controls :: How To Handle Null DateTime

Feb 26, 2010

I get a recordset returned from DB and try to load it. However sometimes field "LastRun" may be empty (NULL). when i have this it compiles fine but errors out when value is null m_LastRun = Convert.ToDateTime(r["LastRun"]); when I take out Convert.ToDateTime it doesn't even compile.

View 3 Replies

DataSource Controls :: Get The Values Even When The Source Or Url Is Null?

Jan 6, 2010

How can i get the values even when the Source or url is null from the below query

SELECT a.id,
isnull((SELECT STUFF((SELECT
'<li><a href="'+url+'">'+Source_Name+'</a>
<span>(' + k.Source +')</span></li>' end
FROM table1 i, table2 k, table3 j where
i.CategoryID = j.Category_ID and i.CategoryID = c.Category_ID and i.Source = k.ID
FOR XML PATH('')),1, 0, '')), '') AS Source_url,
FROM @table4 c INNER JOIN table5 v
on c.Category_ID = v.Category_ID

View 5 Replies

DataSource Controls :: Parse A Null Database Value?

May 18, 2010

I have a datareader like so but when it encounters a NULL database value, I get the error message "Conversion from type 'DBNull' to type 'String' is not valid."

Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Dim yValues As New List(Of Double)
With myReader
If .HasRows Then
While .Read
yValues.Add(Double.Parse(.GetValue(0)))........

View 2 Replies

DataSource Controls :: LocalResourceObject Null When Used By ObjectDataSource

Feb 5, 2010

I have a dropdown list that uses an ObjectDataSource. The select method of the ObjectDataSource needs to localize the TextField, so i create a Dictionary<int, string> and use GetLocalResourceObject as such:

[Code]....

In the Local Resource file, there is status0, status1, and status2, all with a value (Deleted, Active, Inactive). The dropdown and object datasource like:

[Code]....

Now, if I use an ObjectDataSource and put the DropDownList's DataSourceID to it, I will get a null reference on the lookup to the GetLocalResourceObject. BUT If I manually set DataSource/DataBind on the dropdown list on Page_Load, it works fine:

[Code]...

OR If I move the status values to a global resource file and use GetGlobalResource instead of GetLocal, it works fine! Why can I not use an ObjectDataSource and LocalResourceObject in this way?

View 1 Replies

DataSource Controls :: Passing Null To An Integer?

May 3, 2010

i have some problem in passing null value to an integer datatype in sql. Here is my code:-

[Code]....

The if statement within query is where i am having problem!

View 2 Replies

DataSource Controls :: Compare Null Filed In SQL?

Mar 18, 2010

Assume in my table named school has a column named StudentNo

I try this script

select * from school where StudentNo <> 'AA'

I just wondering why this where clause "where StudentNo <> 'AA' always return false when StudentNo is null?

View 9 Replies

DataSource Controls :: Insert Null Value From Sqldatasource?

May 24, 2010

In following SQL query: SELECT DISTINCT CodeID, CodeDesc FROM Faults.TblFltClearCodes AS TblFltClearCodes

I am getting a list but there is no null value.Within this query I would like to get only one NULL value at the top and then the list.How to do this? Explicitly I am not allowed to give a null value in the table in DB.

View 5 Replies

DataSource Controls :: Returning Null Value From Procedure?

Jun 17, 2010

[Code]....

iam using asp.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working

View 1 Replies

DataSource Controls :: Display A NULL Value (of SQL DateType) As 'N/A'?

Aug 24, 2010

My SQL field 'modified' is a DateTime type and if the value is NULL in SQL I want to display a 'n/a' string.
I am using FormView templates to display the value.If I use this statement -> ISNULL(Items.modified,'') AS Modified; I get '1/1/1900 12:00:00 AM' in return.If I use this statement -> ISNULL(Items.modified,'n/a') AS Modified; I get 'Conversion failed when converting datetime from character string.'I could go ahead and change my class from "public DateTime Modified" to "public String Modified" but I want the field to represent its real value which is DateTime.I am not inserting the date value back into the table since the sprocs all take care of that for me. I just want to display the 'n/a' string.So, is there any way to display a SQL DateTime type as a string when its value is NULL inside the table?

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved