RE: Update panel with Gridview control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks for your followup Alex,

Glad to hear that you've got further progress on this.

Regarding on your new questions(deal with empty input parameter of the
TextBox), there are two ideas come up to my mind:

1. You can put the GridView into a panel ,and another GridView(within a
separate panel) on the page. And you can make either one of them visible
depend on the Value in TextBox(whether it is empty or not). And one of the
GridView will alway manually query all the records from table. Also, to
improve performance, you can only perform databinding manually(for that
gridview which display all records) when the TextBox is empty.


2. change the SQL select statement of the SqlDAtaSource control you used.
Add an additinal parameter to control whether it will return all the
records or not:

e.g.

=============================
<asp:SqlDataSource
ID="sqldsOrderDetails" runat="server"
SelectCommand="select * from dbo.[order details] where
orderid=@orderid OR 1 = @display_all"

.................... />



protected void SqldsOrderDetails_Selecting(object sender,
SqlDataSourceSelectingEventArgs args)
{
args.Command.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@orderid", this.txtOrderID.Text));

System.Data.SqlClient.SqlParameter parameter = new
System.Data.SqlClient.SqlParameter("@display_all",
System.Data.SqlDbType.Bit);
if (string.IsNullOrEmpty(txtOrderID.Text.Trim()))
{
parameter.Value = 1;
}
else
{
parameter.Value = 0;
}

args.Command.Parameters.Add(parameter);
}
==============================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

--------------------
From: =?Utf-8?B?QWxleC4gTy4gS29yYW50ZW5n?= <AlexK@xxxxxxxxxxxxxxxx>
Subject: RE: Update panel with Gridview control
Date: Wed, 28 Jan 2009 12:10:03 -0800


Steve,

I have implemented your code changes and the search button is working for
orderid# entered. However, How do I tweak my code such that all records
are
returned when no orderid# is entered. It looks like the change has has to
be
at this line: and maybe adding & "*" but I am not sure. Any suggestions.


protected void SqldsOrderDetails_Selecting(object sender,
SqlDataSourceSelectingEventArgs args)
{
args.Command.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@orderid", this.txtOrderID.Text));
}

""Steven Cheng"" wrote:

Hi Alex,

I've checked the project you sent me. Yes, I got the error when tried
running "trigger1.aspx". Based on the error message and callstack, I
found
that the error occured during the database connection construction, see
callstack below



[ArgumentException: Format of the initialization string does not conform
to
specification starting at index 0.]
System.Data.Common.DbConnectionOptions.GetKeyValuePair(String
connectionString, Int32 currentPosition, StringBuilder buffer, Boolean
useOdbcRules, String& keyname, String& keyvalue) +1242
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable
parsetable, String connectionString, Boolean buildChain, Hashtable
synonyms, Boolean firstKey) +126
System.Data.Common.DbConnectionOptions..ctor(String connectionString,
Hashtable synonyms, Boolean useOdbcRules) +102
<<<<<<<<<<<<<<<<

So I checked the connectionString of the SqlDataSource control used on
that
page and found that you haven't specified the correct connectionString
expression. Here is the original content:

======================
<asp:SqlDataSource
ID="sqldsOrderDetails" runat="server"
SelectCommand="select * from dbo.[order details] where
orderid=@orderid"
SelectCommandType="Text"
ConnectionString="todo"
OnSelecting="SqldsOrderDetails_Selecting"
CancelSelectOnNullParameter="true" />

<p style="background-color:AliceBlue; width:95%">
Example linking the UpdatePanel to a button outside of the panel
that triggers the asynchronous post-back using the
AsyncPostBackTrigger<br
/>
</p>
===================

You need to change the connectionString to the correct one(pointing to
NorthWind database), like below:
==========================

<asp:SqlDataSource
ID="sqldsOrderDetails" runat="server"
SelectCommand="select * from dbo.[order details] where
orderid=@orderid"
SelectCommandType="Text"
ConnectionString="<%$
ConnectionStrings:NorthwindConnectionString %>"
OnSelecting="SqldsOrderDetails_Selecting"
CancelSelectOnNullParameter="true" />

<p style="background-color:AliceBlue; width:95%">
Example linking the UpdatePanel to a button outside of the panel
that triggers the asynchronous post-back using the
AsyncPostBackTrigger<br
/>
</p>
=============================

Then, the page starts working.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments
and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx


--------------------
From: =?Utf-8?B?QWxleC4gTy4gS29yYW50ZW5n?= <AlexK@xxxxxxxxxxxxxxxx>
References: <00F4F0FF-C57B-4A65-B4E3-8265D732D858@xxxxxxxxxxxxx>
<Ro2wVMeeJHA.8120@xxxxxxxxxxxxxxxxxxxxxx>
<1D5E27A4-27FB-40E3-A63B-EC4F6962082E@xxxxxxxxxxxxx>
<iNXFZJreJHA.2052@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE: Update panel with Gridview control
Date: Sat, 24 Jan 2009 16:21:01 -0800


Steve,

Thanks for all your code suggestions. I have added your code and just
made
minor changes to jscript functions and the CustomerNoAjax.aspx page is
working just as expected. However, when I run the Triggers11.aspx page,
I
get
the error below. My goal is make the search button work without hard
coding
the orderid as the author had done. Any suggestions will be admired. I
will
email you my current working version. Also I am getting this minor
error
label:ID property is not specified which I do not see why because in my
solution, I ahve defined the id property
Thanks

Server Error in '/in_depth_update_panel1' Application.

----------------------------------------------------------------------------
----

Format of the initialization string does not conform to specification
starting at index 0.
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.

Exception Details: System.ArgumentException: Format of the
initialization
string does not conform to specification starting at index 0.

Source Error:

An unhandled exception was generated during the execution of the
current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

""Steven Cheng"" wrote:

Thanks for your reply Alex,

If there is anything unclear, please feel free to let me know.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft




.



Relevant Pages

  • RE: Update panel with Gridview control
    ... separate panel) on the page. ... Microsoft MSDN Online Support Lead ... Format of the initialization string does not conform ... connectionString, Int32 currentPosition, StringBuilder buffer, Boolean ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Connection string not working
    ... it is coming up empty. ... Dim ConnectionString As String = ... ConnectionString is nothing after this line. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Connection string not working
    ... is coming up empty. ... Dim ConnectionString As String = ... ConnectionString is nothing after this line. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Exporting excel to text file
    ... filenumber is just a new local variable which is going to hold the system ... >> Thank you so much for your help, the While statement and empty is ... The selection may very large as compared to what is ... >> 'Walk down each row and include it in the string if the cell is not ...
    (microsoft.public.excel.misc)
  • Re: Need an OOP expert for some simple newie questions
    ... I have created a Company class object that contains all the properties ... Public Property CompanyName() As String ... _ConnectionString = String.Empty ...
    (microsoft.public.dotnet.general)