Click here to Skip to main content
15,905,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have a gridview with selectcommand as storedprocedure .I want to pass a parameter value to SP from code behind during a buttonclick .However the value is not passing.Any help will be really appreciated.Thanks in advance.

What I have tried:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:EMPYHT_ConnectionString %>"
SelectCommand="SPGETNAMES" SelectCommandType="StoredProcedure"><SelectParameters>
 <asp:Parameter Name="tnid" Type="String" DefaultValue="" />
   </SelectParameters>
  </asp:SqlDataSource>



protected void but_mep_Click(object sender, EventArgs e)
      {
          string tende=Session["TENDER"].ToString();
          SqlDataSource2.SelectParameters["tnid"].DefaultValue = tende;
          grd_tendermedicineslist.DataBind();
          upnl_editquo.Update();
       }
Posted
Updated 4-Aug-18 9:18am
Comments
Alek Massey 31-Jul-18 14:47pm    
You've checked the session value is returning what you expect?

First off, have you tried debugging your code by setting a break point at your Button Click event for you to verify it it hits there? If it hits, then step into your code and see the value of Session.

Second, when referencing a value from Session object make sure to check for null first to avoid unexpected error. For example:

C#
if(Session["TENDER"] != null){
          string tende= Session["TENDER"].ToString();
          SqlDataSource2.SelectParameters["tnid"].DefaultValue = tende;
}


Third, if you are passing Session value for your Select command, then you can try using the SessionParameter instead. For example:

ASP.NET
<selectparameters>
		<asp:sessionparameter name="ID" sessionfield="Tender" type="Int32" />
</selectparameters>
 
Share this answer
 
https://www.aspsnippets.com/Articles/Bind-data-to-ASPNet-GridView-using-Stored-Procedure.aspx

Try this hope your problem will be solved with this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900