Changing SqlDataSource.SelectCommand At Runtime Breaks Pagination?

Jul 23, 2010

I have a GridView bound to a SqlDataSource with a default SelectCommand defined as such:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:MyConn %>"
SelectCommand="select * from blah blah" />

There are cases where I have to change this query dynamically at runtime, so I do the following:

SqlDataSource1.SelectCommand = sql; // 'sql' is the new query
GridView1.PageIndex = 0;
GridView1.EditIndex = -1;
GridView1.SelectedIndex = -1;

This works just fine actually, but when I click the pagination controls, the result set defaults back to the SelectCommand defined in the SqlDataSource1.

View 2 Replies

Similar Messages:

DataSource Controls :: Dynamically Changing SqlDataSource.SelectCommand From FormView.ModeChanged?

Nov 17, 2010

In an 3.5 web app, I have a page with the following markup/code (this is the brief version, but I believe I got all the relevant info).


The form contains 2 different record types, accessed using the paging controls, depending on the ParentSR field; a parent SR will be something like '1234' while its sub-record will be something like '1234.1'. There are only a few differences in the fields used between the 2 different record types and that is why they are stored in the same table. However, the activity depends on the record type. When browsing from the parent record to the sub-record, the itemtemplate loads fine (notice in the formview's datasource
query, that the sractivity_id field is being pulled along with the subquery value). But when going to edit the record, the page throws an error:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentOutOfRangeException: 'ddlActivity' has a SelectedValue which is invalid because it does not exist in the list of items.

If i click 'back' and retry, it may take 3 attempts, but then the edittemplate will load just fine. I should also point out that this error does not always occur. I've been trying to figure this out for a couple months and it is driving me nuts, mainly due to the fact that I can't reproduce the error in development--it seems to only occurr in production. Anyone with any thoughts on what is going on?

View 1 Replies

What Dynamic SelectCommand In SqlDataSource

Nov 17, 2010

I have a DDL with 2 options: "Trainer" & "Observer." I'd like to use the selection from that DDL to reference a field in the SqlDataSource SelectCommand.

There are 2 fields in the table that may be referenced in the SelectCommand:

"Trainer_Oracle_ID" & "Observer_Oracle_ID." I'm trying to do something like:

WHERE @Oracle_ID_Type = <%=DropDownList_Oracle_ID_Type.Text%>_Oracle_ID

i.e. User selects "Trainer" and the SelectCommand references the field called:


View 6 Replies

DataSource Controls :: Sqldatasource With Inner Join SelectCommand...

Sep 4, 2010

I have a gridview with a sqldatasource with SelectCommand as below:


but it's not workling.....

View 1 Replies

DataSource Controls :: How To Change Selectcommand In Sqldatasource

Oct 11, 2010

i have an SQLdatasource in my page

i was trying to modify it as:

SQL.SelectCommand = "Select * from " + TXT_Tabella.Text;

because i want update dinamically my sql server tables but ,every time i am going to sort, or change page the selectCommand returns as before!

viewState is true! how can i have an SQLdatasource dinamyc by tableName? and how this problem occurs?

View 3 Replies

Using Parameters To Configure The Table Name In An SqlDataSource SelectCommand?

Dec 15, 2010

I have an ASP.NET 3.5 web form with a DropDownList bound to a table of company names in a database. I also have a data bound GridView which I would like to update with data from the database depending on the company name selected in the DropDownList, so that the SelectCommand for the GridView's SqlDataSource is:

SELECT Registration, Telephone, Profile FROM {CompanyName}_VehicleData

Where {CompanyName} is whatever is selected in the DropDownList. I've used the Command and Parameter Editor to create a ControlParameter pointing to the SelectedValue of the DropDownList, but I don't know how to write the SelectCommand query to concatenate the parameter to '_VehicleData'.

View 1 Replies

Forms Data Controls :: DataList And SqlDataSource SelectCommand?

May 27, 2010

In my application, I am using DataList. In Item Template I added One GridView and SqlDataSource to populate data in GridView. DataList having one DataKey field, I want to pass this DataKey Value to the SqlDataSource as Parameter.

I tried this by Using Following:


View 2 Replies

DataSource Controls :: Modifying The SqlDataSource SelectCommand Prior To Loading A Page?

Sep 28, 2010

I have a SqlDataSource setup in the markup on my page. After some new requirements, I am trying to find a way to modify the SelectCommand before the data is filled for the first time. The SelectCommand below will now be used by default since we'll always have the first param. I am faced with a need to modify the SelectCommand though, adding a second session parameter along with it. I tried to override the OnInit method but it didn't seem to still used the default query. Is there a best way to accomplish this? Here is the section of markup I am referring to:


View 2 Replies

Forms Data Controls :: How To Create Selectcommand At Runtime

Sep 30, 2010

I build a DetailsView and assigned datasourceID= SqlDataSource1

I bulid select command at runtime.

string selectcmd = "SELECT * FROM CDInfo WHERE CDID=@id";
SqlDataSource1.SelectParameters.Add("@id", Request.QueryString["id"]);
SqlDataSource1.SelectCommand = selectcmd;
//The only problem is that I try to call the select method
//but the compiler tell me I have to add a DataSourceSelectArguments
//I don't know what argument to add, so I put DataSourceSelectArguments.Empty
// But it says variable "@id" must be decleared
//I don't Know what's going on.

View 4 Replies

Forms Data Controls :: Can't Edit/delete With Gridview Using Dynamic Sqldatasource.selectcommand

Feb 2, 2010

With asp 2.0 and vwd 2005, I have a page with a radiobuttonlist, textbox and gridview with edit/delete. Using the radiobuttonlist, the user selects a search type and then enters the criteria in the text box. the click event of a submit button checks the rbl.selectedindex and chooses a sqldatasource.selectcommand with the where clause getting its criteria from the textbox. The gridview loads the data, but the edit/delete are not working. Code and relevant markup is below




View 3 Replies

Changing User In MVC 2 MockHttpContext Breaks Test?

May 26, 2010

I changed the following line:

private readonly IPrincipal _user =
new GenericPrincipal(new GenericIdentity("someUser"), null /* roles */);


View 1 Replies

Changing Response Type In Aspx Page Breaks In IIS7?

Mar 3, 2010

I have a custom implementation of Application_PreRequestHandlerExecute which is applying a deflate/gzip filter to the response. However, on IIS7, this is failing on my "script generator" pages. These aspx pages take in Query String values and return a custom bit of script, changing the response type to text/javascript. I think it is failing because of the way iis7 uses mime types, but I'm unsure how to fix it short of turning all compressio off.

View 1 Replies

C# - Custom Pagination Vs Default Pagination In A Gridview

Feb 3, 2010

I have the following questions regarding pagination in a gridview.. First as a beginner i used default pagination for all my gridviews..

After checking out some articles on performance they all focus on custom pagination...

Is it a bad practice to use default pagination of a gridview? When to use custom pagination over default pagination in a gridview?

View 1 Replies

DataSource Controls :: Binding GridView With SqlDataSource At Runtime?

Aug 20, 2010

I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. .

View 1 Replies

C# - Changing Image Url During Runtime?

Oct 15, 2010

<asp:Image id="voteaccepeted"
runat="server" class="vote-accept" />

i want to change image url during run time

if( bestanswer == true)
// change url..

how i do it.

View 4 Replies

C# - Changing Where A Resource Is Pulled During Runtime?

Jun 8, 2010

I have a website that goes out to multiple clients. Sometimes a client will insist on minor changes. For reasons beyond my control, I have to comply no matter how minor the request. Usually this isn't a problem, I would just create a client specific version of the user control or page and overwrite the default one during build time or make a configuration setting to handle it.

Now that I am localizing the site, I'm curious about the best way to go about making minor wording changes.

Lets say I have a resource file called Resources.resx that has 300 resources in it. It has a resource called Continue. English value is "Continue", the French value is "Continuez".

Now one client, for whatever reason, wants it to say "Next" and "Apr├Ęs" and the others want to keep it the same. What is the best way to accomodate a request like this? (This is just a simple example).

The only two ways I can think of is to

Create another Resources.resx specific to the client, and replace the .dll during build time. Since I'd be completely replacing the dll, the new resource file would have to contain all 300 strings. The obvious problem being that I now have 2 resource files, each with 300 strings to maintain. Create a custom user control/page and change it to use a custom resource file. e.g. SignIn.ascx would be replaced during the build and it would pull its resources from ClientName.resx instead of Resources.resx.

Are there any other things I could try? Is there any way to change it so that the application will always look in a ClientResources.resx file for the overridden values before actually look at the specified resource file?

View 2 Replies

MVC :: Changing Model Validation At Runtime Programmatically

Jul 9, 2010

I'm starting with MVC 2. Very cool.I have been reading about the data annotations validation attributes that can be set on the view model properties.It's cool but I have a scenario where I need to determine at runtime whether one of the property is required or not.How can I achieve this ? I want to have client side validation enabled too.

View 6 Replies

Web Forms :: Changing A Control Attribute At Runtime?

Oct 19, 2010

I'm basically trying to get a div containing a loading gif to show on my page at runtime. I call it from a button click event as well as in the code flow. It was working before I used the AJAX Update Panels. I've since taken them out as they were causing issues with RegisterClientScriptBlock. By the way, does commenting out the AJAX Markup like this...


...remove them from influence?


My code is initiated from the button click event.


The code that does the work goes like this...


View 5 Replies

DataSource Controls :: Having To Detach SQL Database After Changing And SQLdatasource In Design View?

May 14, 2010

everytime I modify an SQLdatasource using VS wizards, I have to dettach the mdf in VS's server exporer, then hit refresh in the browser, then get the applicaiton is offline error message please remove some pia file, but i usually just count to 12 and then hit refresh again and the page renders properlyhad scoured the forum on more than one ocasstiion, think it has something to do with the Admin rights within SQL, Ive tried the SQL server surface configuration tool, and add administrator stuff, but not sure if i should add (user to provision) something like the thing, or network services or ??also cant figure out where to view which administrators are actually on SQL server,

View 4 Replies

Web Forms :: Changing Title O Sitemapnode At Runtime From Code Behind C#

Aug 15, 2010

I have a site map on my project and I have section which get values from sql database and it changes according to querystring Id value. In my sitemap the title of the page is everytime same. but I want tpo change it at runtime. I am using multiple sitemaps and My sitemap is not the default one. its name is rootSitemap. I tried some code which I got from msdn but it seems doesn't work for me;


Here is my sitemappath code which is situated in my master page;

<asp:SiteMapPath SiteMapProvider="rootSitemap" ID="SiteMapPath1" runat="server"></asp:SiteMapPath>

View 23 Replies

Security :: Changing The Membership / Role Provider At Runtime?

Jul 24, 2010

I started out with the following code which worked fine, no problems:


I've since expanded the above so that it uses different providers according to the current logged in user. Here's the code since my changes:


I'm not getting any error messages but when I view the web page in the browser, it is stuck in a continuous loop where the page displays (correctly), then posts back to the server and displays again.

View 1 Replies

Security :: Programmatically Changing The Profile Provider At Runtime?

Aug 25, 2010

I'm using one application but have multiple providers in my web.config for memberships, roles and profiles to allow my application to be used by different groups of users who need to connect to different databases.

This means I'm having to change the membership, role and profile providers on-the-fly in my code-behind files. So far I've taken care of the membership and roles a bit like this:


However, I'm having trouble finding out how to do the same sort of thing for Profiles. I've looked at ProfileProvider and ProfileManager but I can't work it out how to access my the profile property that I've created in my web.config file called "ScreenSize". Normally you would just write Profile.ScreenSize to read or write to the property.

View 12 Replies

Forms Data Controls :: Changing The Items In The Listview At Runtime?

Feb 2, 2010

There is a page in my project named Messages.aspx that shows the messages received [but obviously], using the ListView control.

I want that the user should be able to see the body of the message on the same page [Messages.aspx] just by clicking the subject of the message, which is ofcourse a link.[Messages.aspx?msg_id=some_id]. Hence the user would actually reload the same page to read the contents of the message.

Now what I want is that I should be able to write some code that would change the <LayoutTemplate> and the <ItemTemplate> of the listview during the runtime. [in the page_load event of course]

Previously the listview would look like this:


After the clicks any message to read it and the page gets loaded, I want the layout of the listview to look like this.


View 2 Replies

Web Forms :: Give Write Permission To Folder For Changing The Image At Runtime

Sep 22, 2010

hw can i give write permission to folder for changing the image at runtime.i have tried so many times but still confused and free hand. can some one pls give me the solution in details.

View 4 Replies

Forms Data Controls :: Creating / Changing Select Parameters In Objectdatasoutce At Runtime?

Jan 17, 2010

suppose that i have a gridview and an objectdatasource in my webform

with that i want to include several search criteria

the problem is that i want theme dynamic

for example

i have a dropdownlit with customers list

the first item in the dropdownlist is "All customers" for example

if i select it no "customer select parameter" is created

otherwise i have a "customer select parameter" for the objectdatasource and it's value is the dropdownlist.selectedvalue

View 2 Replies

Copyrights 2005-15, All rights reserved