Web Forms :: Pass Cookie Value As Parameter To SqlDataSource
Jan 24, 2016asp:querystringparameter assign value how to ...
View 1 Repliesasp:querystringparameter assign value how to ...
View 1 RepliesGridview has many columns and a Delete button as well. Delete button is a control as TemplateField
[code]....
Now associated SQLDataSource's Delete command's stored procedure is expecting two parameters. One is going from DataKeyNames (RowID), other one i wanna pass is the Text of btnDelete (True or False).
i have placed a SqlDataSource component on my aspx page but while configuring the SqlDataSource in the "Test Query" Step I am passing the following parameters :But when i click ok it returns following error:This error occurs when i pass the string :
INFO, WARN, ERROR,
I have tried a lot of combinations but nothing works. It works only if i pass one of the three words in single quotes like this :'ERROR'Infact the INFO WARN and ERROR are the various levels available in the table. Each record can have only one level and in the sql query i am using IN("-----") to match the criteria, hope you understand.
I am using a gridview where i am calling a stored procedure which has 4 input parameters. Out of these 4 parameters, values are to be given such that DomainId = This has to be the row which is to be deleted. This is a primary key Domain = This field has to be passed to SP as NULL. Description= This field has to be passed as NULL. OperationType= This field has to be passed by programmer as some static value say 4 How to i need to specify these here... More details of the Question are here.
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="DomainId"
PropertyName="SelectedValue" Size="4" Type="Int32" />
<asp:Parameter DefaultValue="" Name="Domain" Size="16" Type="String" />
<asp:Parameter DefaultValue="" Name="Description" Type="String" />
<asp:Parameter DefaultValue="4" Name="OperationType" Type="Byte" />
</DeleteParameters>
On running my code using this. I gets an error
Procedure or Function 'spOnlineTest_Domain' expects parameter '@Domain', which was not supplied
I have ASPxDataView and ASPxRadioButtonList within item template. i also have two SQLDataSource's (first fill ASPxDataView, second ASPxRadioButtonList). They are using other database tables connected with the foreign key. Is there any way to pass parameter to my second sqlDataSource (id) to fill RadioButtonList property ? i mean select * from TABLE2 where id = @id ; (@id is a value from TABLE1 which is a value of column returned by first sqlDataSource)
View 3 RepliesI have a datasource with parameters for the SELECT clause and I want to use an asp:CookieParameter but my cookie has several subkeys. For example, the main cookie is named "teres_soft" and the subkey I want to use is "branch_code" so I get this value using a Request.Cookie("teres_soft")("branch_code"). I can easily set such a parameter if my cookie does not have any subkeys but, is it possible to use a cookie's subkey in the SELECT asp:CookieParameter?
View 1 Repliesusing vs2008 writing a asp.net.vb application. I have a datasource on my asp page wich is connected to a gridview. I want to use a cookie value as an input parameter to a stored procedure whose ouput will populate the gridview.
View 7 RepliesI am facing a small issue in using a DropDownList that has only two values (AND and OR) which i want to use to configure a SQL Query in a SqlDataSource. How can i use this thing by passing the value in a SqlDataSource Select Query in such a way to Bind the Result to a GridView. I want something like this -
SELECT [somefields] FROM instinvoice WHERE Namen = @Namen @Option InvoiceNo = @invoiceno where @Namen is from a DropDownList and InvoiceNo is from a TextBox
I m having a problem in specifying this @Option parameter from a DropDownList which contains only two list items - AND and OR. On the Basis of the Selected Value from this DropDownList i want to execute query like
SELECT [somefields] FROM instinvoice WHERE Namen = @Namen AND InvoiceNo = @invoiceno
or
SELECT [somefields] FROM instinvoice WHERE Namen = @Namen OR InvoiceNo = @invoiceno
Using the Query with @Option gives me a Parsing Error. Why is that so. How can I implement this scenario.
I have a Stored Proc which uses a field in the database. that ends up being the user.identity.name. So, when the page loads, it grabs that name and uses it in the stored proc, which I'm which I'm wanting to designate in the sql datasource. But it only gives me choices of querystring, cookie, session, control, etc. My question is how to reference that variable as the parameter in the datasource?
View 3 RepliesHow to use Control Parameter with SQLDataSource When FindControl is required?
[Code]....
I have a details view that is bound to a sqldatasource. The datasource has some extra parameters besides the updated data on the screen, they are;
[Code]....
I am want to take the old values of the details view from the detailsview1_itemupdating event and add them as a parameter to my sqldatasource.
[Code]....
So how can I then add this as a parameter to my sqldatasource?
I have big filter coming from database by using storedprocedure. This stored procedure contains about 12 parameters. In asp.net page I select these values and after doing that I want to pass these values to SqlDataSourec which is bound to gridview. How can I pass these values to SqlDataSource, manually in codebehind?
View 8 RepliesI have a Detailsview grid with an SqlDatasource, this DVG is only going to be used to insert records. The primary purpose of the DS is to populate a DDL control in the insertItem Template that I created my code is this:
[Code]....
The DDL control populates correctly, but when I try to modify the INSERTCommand property in my DS, I try to assign the value to my parameters "TesterID" and "TesterDate" but the only options for controls to pick from, is the DGV but not the DDL in it. I assume it has to do with the InsertItem template but even if I reset it I still cannot pick the textbox as a control that would give the value to my parameters.
I did find a workaroun by build a public method and calling it in the onclick event of the insert button but looks like I have to create another connection to the database which to me seems unnecessary since I already have a DS and everything. how can I do this without having to use my method. here is my method just in case.
[Code]....
So I have a gridview within a gridview (I have a one to many table) my first gridview is working well, but my second gridview has a sqldatasource that has a select parameter(the default value was just for testing)
<asp:SqlDataSource ID="dsCountryByTripID" runat="server" ConnectionString="<%$ ConnectionStrings:bahDatabase %>" SelectCommand="spSelectCitiesByTripID" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter Type="Int32" Name="tripID" DefaultValue="56" /> </SelectParameters> </asp:SqlDataSource>
during my Gridview1 row databound I am trying to grab the columns that match the tripID. But dsCountryByTripID which is my datasource, is only going inputted with the last tripID.
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e) { GridView gv2 = (GridView)e.Row.FindControl("GridView2"); if (e.Row.RowType == DataControlRowType.DataRow) { dsCountryByTripID.SelectParameters.Clear(); DataRowView drv = (DataRowView)e.Row.DataItem; string tripID = (drv["pkiTripId"]).ToString(); dsCountryByTripID.SelectParameters.Add("tripID", DbType.Int32, tripID); //gv2.DataBind(); //e.Row.DataBind(); } }
So I have a gridview within a gridview (I have a one to many table) my first gridview is working well, but my second gridview has a sqldatasource that has a select parameter(the default value was just for testing)
<asp:SqlDataSource ID="dsCountryByTripID" runat="server"
ConnectionString="<%$ ConnectionStrings:bahDatabase %>"
SelectCommand="spSelectCitiesByTripID" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Type="Int32" Name="tripID" DefaultValue="56" />
</SelectParameters>
</asp:SqlDataSource>
during my Gridview1 row databound I am trying to grab the columns that match the tripID. But dsCountryByTripID which is my datasource, is only going inputted with the last tripID.
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
GridView gv2 = (GridView)e.Row.FindControl("GridView2");
if (e.Row.RowType == DataControlRowType.DataRow)
{
dsCountryByTripID.SelectParameters.Clear();
DataRowView drv = (DataRowView)e.Row.DataItem;
string tripID = (drv["pkiTripId"]).ToString();
dsCountryByTripID.SelectParameters.Add("tripID", DbType.Int32, tripID);
//gv2.DataBind();
//e.Row.DataBind();
}
}
I want to add a GridView control to one of my views that is backed by a SqlDataSource. The SelectCommand query is parametrized on the aspnet_Users.UserId GUID for the currently-logged-in user, so I need a way to pass the user ID as a parameter.
I read How to utilize ASP.NET current user name in SqlParameter without code-behind and decided to create a custom Parameter named UserIdParameter:
namespace MyApp.Web
{
public class UserIdParameter : Parameter
{
public UserIdParameter(string name)
: base(name)
{
}
protected UserIdParameter(UserIdParameter parameter)
: base(parameter)
{
}
protected override Parameter Clone()
{
return new UserIdParameter(this);
}
protected override object Evaluate(HttpContext context, Control control)
{
return Membership.GetUser().ProviderUserKey;
}
}
}
In the ASPX view I then added:
<%@ Register TagPrefix="my" Namespace="MyApp.Web" %>
in a line after the <%@ Page ... %> line as well as:
<SelectParameters>
<my:UserIdParameter Name="UserId" />
</SelectParameters>
within the asp:SqlDataSource element.
Unfortunately I get a Parser Error ("An error occurred during the parsing of a resource required to service this request. review the following specific parse error details and modify your source file appropriately.") with the following highlighted in red:
<my:UserIdParameter Name="UserId" />
Visual Web Developer 2010 Express is also informing me that "Element 'UserIdParameter' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing."
Do I need to modify Web.config in some way? If not, what do I need to do to be able to use my custom UserIdParameter parameter?
Being new to using the declarative syntax of SqlDataSource I am trying to figure out a way to set the value of a parameter to a stored procedure. I have a Client_ID that is passed via the Request Object and I need to set the Client_ID before the stored procedure of the SqlDataSource is executed.
Does the stored procedure parameter have to be predefined in the ASPX markup or can it be added dynamically in the code-behind? Would anyone have an example that demonstrates the SqlDataSource markup with a stored procedure and parameter as well as setting that parameter value in code-behind?
I'll try to explain what I'm doing the best I can, but I'm pretty new to asp.net so be patient with me. I have a SqlDataSource which returns a simple select statement based on the WHERE clause using @COURSE_ID
What I want to-do is every time any one of 2 (this will change as it's going to be generated) asp:LinkButtons are pressed, they will change the @COURSEID value which i'd like to associate with the specific button.
Buttons:
<asp:LinkButton ID="LinkButton2" runat="server" onclick="MenuUpdate_Click">Course1</asp:LinkButton>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="MenuUpdate_Click">Course2</asp:LinkButton>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:connString %>" SelectCommand="SELECT Chapter.chapterName, Chapter.chapterID
FROM Chapter
WHERE Chapter.courseID = @COURSE_ID
">
C#
protected void MenuUpdate_Click(object sender, EventArgs e)
{
Parameter p = SqlDataSource1.SelectParameters["COURSE_ID"];
SqlDataSource1.SelectParameters.Remove(p);
SqlDataSource1.SelectParameters.Add("COURSE_ID", THIS NEEDS TO BE VALUE ASSOCIATED TO BUTTON);
ListView1.DataBind();
UpdatePanel1.Update();
}
If anyone has any suggestions that'd be great, I've been trying lots of different things all night with no success :(
For SqlDataSource I can configure the external source for the incoming paramater. For example it might be a QueryString, Session, Profile and so on. However I do not have an option to use User as a source.
I know that I could provide value for the parameter in Inserting,Selecting,Updating,Deleting events. But I do not think that this is an ellegant solution because I have some parameteres already definied in aspx file. I do not want to have parameters defined in two separate places. It makes mess.
So can I somehow define this parameter in .aspx file?
<SelectParameters>
<asp:QueryStringParameter DefaultValue="-1" Name="ID"
QueryStringField="ID" />
//User.Identity.Name goes here as a value for another parameter
</SelectParameters>
I am using the stored procedure below for the select command of a SqlDataSource, and I'm trying to pass a query string parameter, but I get this error:
Procedure or function 'ActivationCampaignGetById' expects parameter '@campaignId', which was not supplied.
The parameter is present in the query string:
http://localhost:62681/Activations/ActivationCampaignDetails.aspx?id=98
Here is my DataSource code:
<asp:SqlDataSource ID="campaignDataSource" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ProVantageMediaManagement %>"
SelectCommand="ActivationCampaignGetById" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="98" Name="campaignId"
QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
And my stored procedure declaration:
ALTER procedure [dbo].[ActivationCampaignGetById]
@campaignId int
as
select
I am using the stored procedure below for the select command of a SqlDataSource, and I'm trying to pass a query string parameter, but I get this error:
Procedure or function 'ActivationCampaignGetById' expects parameter '@campaignId', which was not supplied.
The parameter is present in the query string:
http://localhost:62681/Activations/ActivationCampaignDetails.aspx?id=98
Here is my DataSource code:
<asp:SqlDataSource ID="campaignDataSource" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ProVantageMediaManagement %>"
SelectCommand="ActivationCampaignGetById" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="98" Name="campaignId"
QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
And my stored procedure declaration:
ALTER procedure [dbo].[ActivationCampaignGetById]
@campaignId int
as
select
[code]....
Is ther a way I can tie DataSource to SqlDataSource on aspx page and pass select parameters?
I have GridView1 and SqlDataSource1. I use EnableEditing to GridView1. This is Code of GridView
<
asp:GridView
ID="GridView1"
Width="100%"
runat="server"
AutoGenerateColumns="False"
BackColor="White"
BorderColor="#3366CC"
BorderStyle="None"
BorderWidth="1px"
CellPadding="4"
DataKeyNames="DoctorID"
DataSourceID="SqlDataSource1">
<RowStyle
BackColor="White"
ForeColor="#003399"
/>
<Columns>
<asp:BoundField
DataField="DoctorID"
HeaderText="DoctorID"
InsertVisible="False"
ReadOnly="True"
SortExpression="DoctorID"
/>
<asp:BoundField
DataField="DoctorName"
HeaderText="DoctorName"
SortExpression="DoctorName"
/>
<asp:BoundField
DataField="City"
HeaderText="City"
SortExpression="City"
/>
<asp:BoundField
DataField="Str"
HeaderText="Str"
SortExpression="Str"
/>
<asp:BoundField
DataField="StrRegion"
HeaderText="StrRegion"
SortExpression="StrRegion"
/>
<asp:BoundField
DataField="StringLevels"
HeaderText="StringLevels"
SortExpression="StringLevels"
/>
<asp:BoundField
DataField="Streat"
HeaderText="Streat"
SortExpression="Streat"
/>
<asp:BoundField
DataField="Email"
HeaderText="Email"
SortExpression="Email"
/>
<asp:BoundField
DataField="Mobile"
HeaderText="Mobile"
SortExpression="Mobile"
/>
<asp:BoundField
DataField="HomePhone"
HeaderText="HomePhone"
SortExpression="HomePhone"
/>
<asp:BoundField
DataField="ClinicPhone"
HeaderText="ClinicPhone"
SortExpression="ClinicPhone"
/>
<asp:BoundField
DataField="Fax"
HeaderText="Fax"
SortExpression="Fax"
/>
<asp:BoundField
DataField="address_details"
HeaderText="address_details"
SortExpression="address_details"
/>
<asp:BoundField
DataField="Expr1"
HeaderText="Expr1"
SortExpression="Expr1"
/>
<asp:BoundField
DataField="VisitPlaceStr"
HeaderText="VisitPlaceStr"
SortExpression="VisitPlaceStr"
/>
<asp:CommandField
ShowEditButton="True"
/>
</Columns>
<FooterStyle
BackColor="#99CCCC"
ForeColor="#003399"
/>............
I have the need to display a date in this format: dd/mm/yyyy. This is actually being stored in an ASP.NET textbox and being used as a control parameter for a select on the GridView. When the query is run, though, the date format should change to 'd M y' (for Oracle). It is not working. Can someone tell me what I'm doing wrong? Right now I am pushing the "new" format to a invisible label and using the label as my control param:
$(document).ready(function() {
//datepicker for query, shown traditionally but holding an Oracle-needed format
$('[id$=txtBeginDate]').datepicker({ minDate: -7 , altFormat: 'd M y' });
//get alt format
var altFormat = $('[id$=txtBeginDate]').datepicker("option", "altFormat");
//set date to be altformat
$('[id$=lblActualDate]').datepicker("option", "altFormat", 'd M y');
});
I have an SqlDataSource query that should use an input parameter for multiple integer values, like:
select * from table1 where TableID IN (1,2,3,4,5)
->
select * from table1 where TableID IN (@IDValues)
How do I do that ? Default parameter settings won't work, returning "invalid integer value" . I suppose that parameter should be passed as some kind of array that SQL recognizes as multiple integer values , but what's the correct way of setting this ?