SQL Server :: Add Parameter To SqlDatasource With Update In GridView?
Jul 25, 2010
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"
/>............
View 1 Replies
Similar Messages:
Feb 4, 2010
I have two image buttons in a gridview, one to approve the opening of the record and one to approve the closing of the record. I have added a CommandName to each button (OpenApproved and CloseApproved) and in the grids rowcommand I would like to update the database with the Username of the person clicking the button, Username goes into either the OpenLeadApprover or CloseLeadApprover field depending on which button is pressed. The grid has a sqldatasource with an Update stored procedure which has three parameters, @WorkOrderIDWhat I have tried to do in the RoeCommand event is declare a variable for the sqldatasource and add the parameter value to it, then run the update command. Here is the code:
[Code]....
View 4 Replies
Jan 9, 2010
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?
View 2 Replies
Apr 7, 2010
Gridview 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).
View 1 Replies
Nov 4, 2010
I have a gridview that displays the contents of a database table, using an sqlDataSource. That part (including inserting, updating and deleting rows) works perfectly. What I am wanting to do is add a "search" function to restrict the rows returned to a user entered name. I have a textbox for the name to be searched and a "Search" button in the headertemplate as such:
[Code]....
The DataBind fails, with the error:
Could not find control 'txtSearchName' in ControlParameter 'username'.
View 1 Replies
Aug 2, 2010
I have an user control placed on a content page. The content correctly receives the session variables. In the user control I have the following
1. The pageload fires and the text box is correctly set.
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (Session["app_id"] != null)
{
txtAppId.Text = Session["app_id"].ToString();
}
</script>
2. I have datagrid in the usercontrol which has a binding variable tied to a control parameters as follows
<asp:SqlDataSource ID="SqlDataSourceMain" runat="server"
ConnectionString="Myconnectionstring"
ProviderName="MyProvider" SelectCommand="select
last_name,first_name
from applications
where (id = to_number(:pAppId))">
<SelectParameters>
<asp:controlparameter name="pAppId" controlid="txtAppId" propertyname="Text" />
</SelectParameters>
<SelectParameters>
<asp:controlparameter name="pAppId" controlID="txtAppId" propertyname="Text"
Direction="InputOutput" Type="Int32" ConvertEmptyStringToNull="True" />
I tried the following, same error
</SelectParameters>
<asp:SessionParameter
ConvertEmptyStringToNull="True"
DefaultValue="0"
Direction=" InputOutput "
Name="pAppId"
SessionField="app_id"
Size="integer"
Type="String" />
</asp:SqlDataSource>
For some reason the select parameter pAddId is getting set to null and get the following error when the content page is loaded If I hard code the value it works RA-01036: illegal variable name/number 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: Oracle.DataAccess.Client.OracleException: ORA-01036: illegal variable name/number
View 1 Replies
Jun 19, 2010
I want to send multivalued parameter to SQLdatasource via gridview control.
My slect query is like
SELECT * FROM FRUITS
WHERE FruitID IN(@FruitIDs)
how can i achieve that?
View 6 Replies
Sep 27, 2010
I have a vb.net page that has an optional parameter. If a user enters data for that field, and clicks save, it saves fine via the stored procedure. HOWEVER, if the user changes their mind, and wants to erase the data they entered, they go to the text field, and delete the characters, and click save, but no matter what, the stored procedure will not save the fact that they erased the data (it won't set it back to NULL). If the user enters a space, the stored procedure will save the space, and if they enter different data, it will save the other data. I can't figure out how to get it back to letting them set it to Null? I think this is because it's an optional parameter, and the stored proc is used by several forms (Some of those forms do not include this parameter), but this form utilizes that optional paramater.
Here's my stored procedure...
[Code]....
[Code]....
View 2 Replies
Mar 28, 2011
I am trying to get a parameter for my update from the gridview but it is an ID column that I do not want displayed. If I display the data in a boundfield it works fine but if I set the visibility to false the parameter is no longer sent to the update stored procedure. There does not appear to be a hiddenfield column that I can put into the gridview.I have tried to set the parameters through the code behind but I am not certain on how to access the data I want the following code does not work (It sets the parameter to nothing
Protected Sub grvFacilityDisciplineBillingRate_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles grvFacilityDisciplineBillingRate.RowUpdating
Dim row As GridViewRow = grvFacilityDisciplineBillingRate.Rows(e.RowIndex)[code]...
And this is the front end with the two ID columns displayed, which is not what I want
<asp:SqlDataSource ID="sqlDisciplineBillingRate" runat="server" DataSourceMode="DataSet" SelectCommandType="StoredProcedure" SelectCommand="SP_Facility_DisciplineBillingRates" UpdateCommandType="StoredProcedure" UpdateCommand="SP_DiscplineBillingRate_Update" ConnectionString="<%$ ConnectionStrings:Trustaff_ESig2 %>">[code]....
View 2 Replies
Feb 9, 2010
I am building a web site, it's used to manage the data in SQL server so the another web site(connect to the same SQL database) can receive the new infoSo far I've build 2 parts, one manages the news system, the another manages the album system, news manage system work perfect, when I update, add or delete news form the web site (using sqldatasource, INSERT, DELETE and UPDATE command), the data inside SQL changes as well.
View 2 Replies
Oct 20, 2010
I have a Gridview where I can modify the Time portion of a DateTime field. The update method is working well, except for one thing:The field should only allow the time portion, e.g 08:23:09 but on the Database it saves it as a full DateTime, e.g 10/18/2010 08:23:09 AM. The problem is that upon editing, instead of adding the existing Date portion, it adds the current Date portion. So if I am editing the item from the last example into 08:25:09 instead of adding it as 10/18/2010 08:25:09 AM it adds it as 10/20/2010 08:25:09 AM which is obviously undesired behavior.Here's how I am doing the update:
protected void grvOutHour_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridView grvOutHour = (GridView)this.grvReport.Rows[grvReport.EditIndex].FindControl("grvOutHour");
TextBox txtBox = (TextBox) grvOutHour.Rows[e.RowIndex].FindControl("txtEditOutHour");
[code]...
View 1 Replies
Dec 14, 2010
i couldnt find a specific answer to this question, i am relatively new to .net :)
i have a gridview that is displaying data from a sqldatasource in my page_load event. i need to loop through the records and update each value of a particular column BEFORE being set into the GridView.
i have tried converting to a data set and looping through updating the values, however it seems that one i initially run my query the values get set right into the GridView and i can't update them after that.
Do I need to add one of the GridView functions like Databound and do the loop in there?
View 5 Replies
Aug 26, 2010
Is it possible to use a SQLDataSource to populate a gridview but not use the SQLDataSource for Updating?
I wanted to add the update code in the Gridview_RowUpdating event since it is a complex update I need to do.
I get this message when i click the update button
Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.
View 4 Replies
May 19, 2013
in my asp.net+access web code in vb. There is three labels named (tata.text,tvs.text,msu.text) is there any option on clicking on the label named tata.text the data pertaining to tata be displayed in a gridview in another page or a popup display in same page.
View 1 Replies
Oct 26, 2010
I'm having a gridview in my aspx page with checkbox, User can select one or more than one record(s) at a time and clicks on delete button, Then i'm constructing an object of my DTO and adding all the checked row's Primary Key (DataKeyNames - GUID's in my case) to a serializable class and generating an XML and sending it as parameter to the Stored Procedure.
My Doubt is, can i bulk delete all the rows from database table those are present in my XML document??
If it works, I can do bulk update with XML only, i already did bulk insertion by generating an XML..
My Another Question is, Will it affect the performance? Each time when i construct an DTO object and adding it to the Generic List?
Which one is better, I mean ObjectDataSource or SQLDataSource or my XML method?
[code]....
View 3 Replies
Nov 5, 2010
during edit mode i populate the drop down in question with data based on a value selected in another drop down also in the gridview, all works find, but the paramater is not being updated with the selected value, i think this is because i do not call any Bind in the aspx side.
<asp:TemplateField HeaderText="Build Types">
<ItemTemplate>
<asp:Label ID="lblBuildTypes runat="server" Text='<%# Bind("BuildType") %>'></asp:Label>
</ItemTemplate>
[Code]....
View 2 Replies
Aug 12, 2010
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(); } }
View 1 Replies
Aug 11, 2010
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();
}
}
View 2 Replies
Jan 17, 2011
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?
View 2 Replies
Nov 9, 2010
Here is the sqldatasource config code: <asp:SqlDataSource ID="SqlDataSource1" runat="server"
View 1 Replies
Sep 16, 2010
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.
View 2 Replies
Mar 16, 2011
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?
View 1 Replies
Apr 10, 2010
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 :(
View 1 Replies
Oct 5, 2010
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>
View 1 Replies
Jul 1, 2010
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
View 8 Replies