sqldatasource

Cannot Find Control ID in ControlParameter

≯℡__Kan透↙ 提交于 2019-12-06 04:57:25
I am trying to insert values from a textbox but I get an error that it cannot find the controlid in the controlparameter. The TextBox is inside a formview, which is inside a listview. The SqlDataSource is outside the ListView. My InsertButton_Click Method protected void InsertButton_Click(object sender, EventArgs e) { var ctrl = (Control)sender; var formview = (FormView)ctrl.NamingContainer; formview.ChangeMode(FormViewMode.Insert); SectionListView.DataSource = SectionDataSource; SectionListView.DataBind(); } The InsertItem Template <InsertItemTemplate> <tr style=""> <td> <div style="font-size

How to specify parameter value for stored procedure in SqlDataSource

限于喜欢 提交于 2019-12-06 02:41:58
问题 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. I have a couple of questions. 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

Dynamic WHERE clauses in a SqlDataSource

非 Y 不嫁゛ 提交于 2019-12-05 14:04:16
I'm using a SqlDataSource in a very simple application. I'm allowing the user to set several search parameters for the SDS's select command via TextBoxes, one TextBox per parameter (think txtFirstName, txtLastName, etc). I'm planning on using a button click event handler to set the SqlDataSource's SelectCommand property which by default will return all records (for my purposes here). I want to refine this select command to possibly add one or more WHERE clauses depending on if the user enters search criteria in any of my TextBoxes. Example in case I'm not being clear: By default, my

How to hide gridview column after databind?

拟墨画扇 提交于 2019-12-05 04:55:20
问题 I hide my columns using the solution in following link How to hide a TemplateField column in a GridView However this causes problems with update operations, as gridview acts as hidden rows has null value. So how to hide columns after databind? protected void begv_OrderDetail_RowCreated(object sender, GridViewRowEventArgs e) { ((DataControlField)begv_OrderDetail.Columns.Cast<DataControlField>().Where(fld => fld.HeaderText == "FileNo").SingleOrDefault()).Visible = "False"; } 回答1: Try this,

asp:QueryStringParameter and empty query string parameter

眉间皱痕 提交于 2019-12-05 03:28:01
I have asp:GridView displaying client requests using asp:SqlDataSource . I want to limit displayed information by client: View.aspx has to display everything, View.aspx?client=1 has to display only requests from client ID #1. So I'm using <asp:QueryStringParameter Name="client" QueryStringField="client" /> for query "EXEC getRequests @client" . Everything works properly when some client is specified. But don't - if not. I tested my SP using SSMS - it works properly in both cases - when parameter is specified and when it isn't ( NULL passed explicitly). What have I do? SqlDataSource won't fire

Setting DateTime as a SqlDataSource parameter for Gridview

夙愿已清 提交于 2019-12-04 13:42:35
Hey I would like to display certain data with my stored procedure for the last 30 days. here is what I have done (aspx.cs file): protected void Page_Load(object sender, EventArgs e) { DateTime toDate, fromDate; toDate = DateTime.Now; fromDate = toDate.Subtract(new TimeSpan(31, 0, 0, 0)); SqlDataSource1.SelectParameters.Add("fromDate", DbType.DateTime, fromDate.ToString()); SqlDataSource1.SelectParameters.Add("toDate", DbType.DateTime, toDate.ToString()); } here is my aspx file <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

SqlDataSource SelectCommand using LIKE does not work

China☆狼群 提交于 2019-12-03 23:05:24
I have the following T-SQL in a SelectCommand : SELECT h.Business, hrl.frn FROM registration hrl INNER JOIN holder h on h.call = hrl.call WHERE (h.Business like '%' + @business + '%' and h.Business is not null) and (hrl.frn = @frn and hrl.frn is not null) business and frn are tied to control parameters and it should return data even if one or both is left blank, but if I put in data just for frn for example, it does not return anything. I think my T-SQL is not doing the right thing and I am also not sure if I am handling the like correctly. if both textboxes are left empty, it should return

How to hide gridview column after databind?

你。 提交于 2019-12-03 22:15:44
I hide my columns using the solution in following link How to hide a TemplateField column in a GridView However this causes problems with update operations, as gridview acts as hidden rows has null value. So how to hide columns after databind? protected void begv_OrderDetail_RowCreated(object sender, GridViewRowEventArgs e) { ((DataControlField)begv_OrderDetail.Columns.Cast<DataControlField>().Where(fld => fld.HeaderText == "FileNo").SingleOrDefault()).Visible = "False"; } Try this, grid1.Columns[columnIndex].Visible= false; Edit based on comment of questioner, for getting values of hidden

How to set parameters for SqlDataSource UpdateCommand

淺唱寂寞╮ 提交于 2019-12-02 12:39:21
For a Gridview: I am trying to use a stored procedure for the first time in a SQLDataSource for the UpdateCommand: <asp:SqlDataSource ID="TECT_DataSource" runat="server" ConnectionString="<%$ ConnectionStrings:OracleConnectionString %>" ProviderName="<%$ ConnectionStrings:OracleConnectionString.ProviderName %>" SelectCommand="SELECT MPID, User_Id, Last_Name, First_Name FROM Scripts.vw_Tect_Exam" UpdateCommand="P_TECT_UPD_EXAM_ID" UpdateCommandType="StoredProcedure"> <UpdateParameters> <asp:Parameter Name="MPID" Type="Int32" /> <asp:Parameter Name="User_Id" Type="String" /> </UpdateParameters>

GridView RowUpdating SqlDataSource.Update from CodeBehind

為{幸葍}努か 提交于 2019-12-02 09:41:10
问题 So I am having an issue with doing an update in a Gridview during an OnRowUpdating event. What I am trying to do is set the UpdateCommand in an SqlDataSource then update using that command. The event is firing okay, but when the event is done it appears that the row never updates. C#: protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { SqlDataSource1.UpdateCommand = "UPDATE A_Table SET Something = @AValue WHERE ID = " + e.RowIndex; SqlDataSource1.Update(); } Edit: