DataSource Controls :: Passing A Variable In A SelectCommand?

Jul 7, 2010

I am trying to pass a variable within a selectcommand statment in ASP.NET and I have researched online how to do it but I can't seem to find a way to do it...What I am trying to do is write a code for a web page that will display a page with useful links on it where the links are separated into different topics and where everything is dynamically grabbed from a database. This is what I have so far:

<!-- Start MainContentRegion -->
<h1>Useful Links</h1>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"

[]code...

View 4 Replies


Similar Messages:

Pass An Asp Variable To A Selectcommand?

Apr 8, 2010

I am trying to pass a variable "PIN2" that I am retrieving like below to a SelectCommand statement in a asp SqlDataSource tag

<%
Dim PIN As String = Request.ServerVariables("LOGON_USER")
Dim PIN2 As String = Right(PIN, 6)
%>

View 1 Replies

Web Forms :: Retrieving SelectCommand From Session Variable

Feb 4, 2010

What is wrong with this code:

[Code]....

I am getting error message:

C:ProjectsMattBookQuestExport.aspx(123): Build (web): Literal expressions like '<%$ ConnectionStrings:BookList %>' are not allowed. Use <asp:Literal runat="server" Text="<%$ ConnectionStrings:BookList%>" /> instead.
C:ProjectsMattBookQuestExport.aspx(124): Build (web): Literal expressions like '<%$ ConnectionStrings:BookList.ProviderName %>' are not allowed. Use <asp:Literal runat="server" Text="<%$ ConnectionStrings:BookList.ProviderName%>" /> instead.
C:ProjectsMattBookQuestExport.aspx(125): Build (web): Literal expressions like '<%$ Session["SelectCommand"] %>' are not allowed. Use <asp:Literal runat="server" Text="<%$ Session["SelectCommand"]%>" /> instead.
Without SelectCommand I can compile.

View 7 Replies

DataSource Controls :: How To Get Sqldatasource1.selectCommand Value

Mar 30, 2011

How to get sqldatasource1.selectCommand value

[Code]....

i want to set that if nothing return i will display a msg to users.

View 7 Replies

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

Sep 4, 2010

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

[Code]....

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

DataSource Controls :: SelectCommand String Is Too Long?

Dec 21, 2010

My SelectCommand string in my asp:SqlDataSource is very long. Is there a way I can chop it up into different strings on several newlines to make it more readable?

View 4 Replies

DataSource Controls :: Pass QueryString In SelectCommand From Code Front?

Jan 7, 2011

I have a question related to <asp:SqlDataSource's SelectCommand. How to pass a querystring like <%# Eval("PhotoID") %> in the selectCommand. The whole frontend code is attached. I put

<%# Eval("PhotoID") %> and the photoid gets printed in the page.
<%# Eval("PhotoID") %> is the current displayed picture's PhotoID.

I want to pass this PhotoID or I want to pass <%# Eval("PhotoID") %> to the select command dynamically. I have tried the following approaches:

1) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = @pID"> <SelectParameters><asp:Parameter Name="pID" DefaultValue="7" /></SelectParameters> </asp:SqlDataSource> The above works but it gives only information about PhotoID 7, but there are other photos; How to set pID's value to <%# Eval("PhotoID") %> in ASP .NET's frontend page? then I also tried,

2) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = <%#'Eval("PhotoID') %>"></asp:SqlDataSource> Gives Parser error: Parser Error Message: The server tag is not well formed.

What I should do so that I can pass current PhotoID to SelectCommand? The frontend code:

<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Your Name Here | Picture Details"
CodeFile="Details.aspx.vb" Inherits="Details_aspx" %>
<asp:content id="Content1" contentplaceholderid="Main" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="shim solid"></div>
<div class="page" id="details">
<%--Update Panel Here--%>
<asp:UpdatePanel runat="server" ID="updatepanel">
<ContentTemplate>
<asp:formview id="FormView1" runat="server" datasourceid="ObjectDataSource1" cssclass="view"
borderstyle="none" borderwidth="0" CellPadding="0" cellspacing="0" EnableViewState="false" AllowPaging="true">
<itemtemplate>
<div class="buttonbar buttonbar-top">
<a href="Albums.aspx"><asp:image ID="Image1" runat="Server" skinid="gallery" /></a>
<asp:ImageButton ID="ImageButton9" Runat="server" CommandName="Page" CommandArgument="First" skinid="first"/>
<asp:ImageButton ID="ImageButton10" Runat="server" CommandName="Page" CommandArgument="Prev" skinid="prev"/>
<asp:ImageButton ID="ImageButton11" Runat="server" CommandName="Page" CommandArgument="Next" skinid="next"/>.................

View 14 Replies

DataSource Controls :: How To Create A Query In Gridview Selectcommand Without The Code Behind

Dec 1, 2010

how to query the system date in selectcommand in gridview without using the codebehind. using c# .net

my code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM tablename where date_today = <SYSTEMDATE>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName
%>"

View 1 Replies

DataSource Controls :: Maintaining A Custom SelectCommand Across Page Loads?

Feb 19, 2011

My SqlDataSource has no selectCommand defined in the .aspx page. Instead I define it in the code behind dynamically depending on some parameters that the user selects and then clicks a button to perform the query (custom search filters basically). The problem is that when I click on a different page in my dataPager, or I click to sort any of the columns the gridview becomes empty when the page refreshes. I did a check and the selectCommand becomes empty when the page posts back. Is there a way to prevent this from happening?

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 help...it still used the default query. Is there a best way to accomplish this? Here is the section of markup I am referring to:

[code]....

View 2 Replies

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

Nov 17, 2010

In an asp.net 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).

[Code]....

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

DataSource Controls :: Filter - Select Date In Ddl And Use Selectedvalue In Gridview SelectCommand

Nov 7, 2010

I've got a gridview which works fine. I use dropdownlists which are filled with distinct values of the columns. So when I select an item in a drompdownlist the gridview refreshes based on the selected value. When I have a column which uses string values, I can start the filter with a default % value to use in my select paramaters. But when I have a date column, I can't use that. I use a datasource for the gridview and I prefer to leave codebehind out if this is not needed. Now I use >= in my gridview select to show all rows. but I want to use only = to make the filter work correct when I select a date in the ddl and use the selectedvalue in the gridview selectCommand

<asp:DropDownList ID="ddlUpdateDatum" DataSourceID="dsPopulateUpdateDatum"
AutoPostBack="true" DataValueField="UPDATEDATE" runat="server"
CssClass="selectinput" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="01/01/1900"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateUpdateDatum" runat="server"
ConnectionString="<%&#36; ConnectionStrings:GAMSYSTEMSqlServer %>"
SelectCommand="SELECT DISTINCT(UPDATEDATE) FROM [messages] ORDER BY UPDATEDATE ASC ">
</asp:SqlDataSource>
And I use this in the gridview datasource:
<asp:SqlDataSource
runat="server"
ID="dsGridview"
ConnectionString="<%&#36; ConnectionStrings:DBSqlServer %>"
SelectCommand = "SELECT * FROM [messages] WHERE AND UpdateDatum >= @UpdateDatePar ORDER BY UpdateDatumDESC"
>
<SelectParameters>
<asp:ControlParameter Name="UpdateDatePar" ControlID="ddlUpdateDate" PropertyName="SelectedValue" Type="string" />
</SelectParameters>

View 2 Replies

DataSource Controls :: Dynamic SelectCommand Won't Be Passed After Partial Page Update?

Mar 11, 2010

I have a page has Listview and Datapager inside UpdatePanel. When I refresh the new SQL results and bind by pressing link buton outside of the update panel, I get correct results. (get new SQLselect statment, rebind to listview, update updatepanel)

However, the SelectCommand is not bound right or some other reason, if I press datapager, I won't get no results.

I'm guessing it's caused by not passing new dynamic selectcommand since my datapager and listview works first update.

View 4 Replies

Forms Data Controls :: Passing A Variable To Onclientclick?

Mar 10, 2011

I cant get this right

[Code]....

Where PKey is a variable that holds the Datakey

View 8 Replies

Forms Data Controls :: Passing Hidden Variable Value In DataNavigateUrlformatstring?

Jan 24, 2011

I am using ASP.NET 2.0 and C#. I have a gridview, which has a datanavigateurlformatstring, in which i am passing data in the gridview as querystrings.I have a hiddenvariable in the page. i would like to pass the hidden variable to the gridview in the datanavigateurlformatstring.Currently i have the gridview and hidden variable like this:

[Code]....

How to pass the hiddenfield value in the datanavigateurlformatstring?

View 3 Replies

DataSource Controls :: Variable Connection String Parameter In A DataSource Control

May 20, 2010

I have several web forms which use a GridView linked to a DataSource control which is defined at design time as follows:

<cc1:pgsqldatasource
id="dsStates"
runat="server"
connectionstring="<%&#36; ConnectionStrings:PgSqlConnection %>"
oldvaluesparameterformatstring="Original_{0}"
providername="<%&#36; ConnectionStrings:PgSqlConnection.ProviderName %>" >
</cc1:pgsqldatasource>

As you can see, the connectionstring parameter is defined to a specific connection string name and I need to be able to set such a parameter to a different value, for example, to a session variable content.

View 1 Replies

DataSource Controls :: Access Property Of Object As Session Variable As Declarative Datasource Parameter Value

Oct 27, 2010

I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:

[Code]....

However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />

View 2 Replies

DataSource Controls :: Passing Parameter To Datasource In Code Behind?

Mar 25, 2010

I need to pass the control parameter to Sql Datasource in code behind,

<asp:ControlParameter ControlID="DDL_RType" Name="rtype" PropertyName="SelectedValue"

View 3 Replies

Forms Data Controls :: Passing A Variable To Data Source Query?

Feb 26, 2010

I'm using the DetailView control to display employee details from a specfic company, but it seems when I try to create the query in the data source wizard I'm unable to select the variable for the WHERE clause, only the web pages control components.

The employees are selected through the company name which is entered at the beginning of the page and in turn is used to select the company id.

View 2 Replies

Passing Page As A Variable?

May 27, 2010

I have this sub in a class modulePublic Shared RunMySub(ByVal P as Page) 'I need page ref in the class sub to clear cache like

P.Cache.Remove("MyCache")
end sub

When I call this sub 'RunMySub' from a page, it works fine, ok, great !BUT now I need to run it from another class module...so I did this

Dim mpage As New Page
RunMySub(mpage)
mpage = Nothing

I get the error : Cache not available...How can I pass a page from another class module , thats not a page, or some how manage cache functions on a class module without pass the page varible ???

View 2 Replies

Passing Javascript Variable To C#?

Nov 15, 2010

I just need to know how to pass a javascript variable to c# when i click on a button

View 2 Replies

ADO.NET :: Passing String Variable To SQL

Feb 22, 2011

I have this string variable:
[Code]....

I want to pass the string MON to the sql query: to replace trunc(sysdate) .
[Code]....

View 3 Replies

Passing Variable From Event To Page_Load?

May 19, 2010

I am thinking this is a pretty simple problem... but I can not get it to function.I just want to get the calendar control to change a date which subsequently modifies a database select statement. I can get the current code to process without error, but the variable set is always a click earlier. Of course, I want the variable to be set upon any change in the calendar control.

public partial class NewBusinessReport : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

[code]...

Does this make sense? I just want it so that when SelectionChanged gets fired the Calendar1SelectCommandDate passes the correct date to the Page_Load page. The error I get now is:"The name 'Calendar1SelectCommandDate' does not exist in the current context"I get that the variable does not exist in the context. That actually seems to make sense based on what I have coded; however, I try to get that variable established and I still seem to be headed in the wrong direction.Basically, I have four calendar controls, one for a date (period 1 start, end and then period 2 start, end). I want to set the program so any change in that date sets off a new Select statement into the SQL server.

View 1 Replies

VS 2008 Passing A Variable Between Two Protected Subs?

Aug 31, 2010

I hope this is simple but I can't find any information when searching Google about passing a variable between two Protected Subs.

When I use the fileUpload tool within my webform I need to take the filename chosen and use it in a different Protected Sub

View 8 Replies







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