I have asp.net page with SQL server 2008 as database. I have 3 stored procedures . one for total count of users in tbl_users and onother for total man users and last for woman users. and i have 3 labels for display count of records. I Want to give link to the labels so that when we click on label, open another page and run related stored procedure. and show detail in grid view. For eg : enter image description here
<a href="show_records.aspx?val="+Label1.Text;"><asp:Label ID="lbl_total_records" runat="server"
</asp:Label></a>
But this code dont work . please help me.
Use the LinkButton
control instead:
<asp:LinkButton runat="server" ID="lnk_total_records" />
This functions the same as an HTML anchor tag but allows you to set the attributes from the code behind like so:
protected void Page_Load(object sender, EventArgs e)
{
lnk_total_records.Text = "LinkText";
lnk_total_records.PostBackUrl = "show_records.aspx?val=LinkText";
}
I think what you are trying to do is this:
<a href="show_records.aspx?val=<%=lbl_total_records.Text%>"><asp:LabelID="lbl_total_records" runat="server" Text="1"></asp:Label></a>
This will properly concatenate the text of the label to your link. The "<%= %>" tags are shortcut for Response.Write().
You can then get the value from your query string on the show_records.aspx page like this:
if (Request.QueryString["val"] != null)
{
string value = Request.QueryString["val"].ToString();
//logic here to call the correct stored procedure based on value
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.