Hello Friends, 我有代码,通过点击动态生成的链接按钮,从Session中的数据库中获取值。我想将这些值重定向到另一个页面,我的代码就在这里..
Hello Friends, I have code, to pick up the, values from database in Session, By Clicking on Dynamically Generated Linkbutton. I want to redirect those values to another page, my code is here..
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Configuration; public partial class Dynamic_link : System.Web.UI.Page { SqlConnection cnn = new SqlConnection(); protected void Page_Load(object sender, EventArgs e) { cnn.ConnectionString=ConfigurationManager.ConnectionStrings["jin"].ConnectionString; if(cnn.State==ConnectionState.Closed) { cnn.Open(); } SqlCommand cm = new SqlCommand("select itemname from menu", cnn); cm.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cm); DataSet dt = new DataSet(); da.Fill(dt); Repeater Repeater1 = new Repeater(); Repeater1.DataSource = dt; Repeater1.DataBind(); if (cnn.State == ConnectionState.Open) { cnn.Close(); } foreach (RepeaterItem repeatItem in Repeater1.Items) { // if condition to add HeaderTemplate Dynamically only Once if (repeatItem.ItemIndex == 0) { RepeaterItem headerItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Header); HtmlGenericControl hTag = new HtmlGenericControl("h4"); hTag.InnerHtml = "Menu Collection"; repeatItem.Controls.Add(hTag); } // Add ItemTemplate DataItems Dynamically //SqlDataReader dr = Int32.Parse; RepeaterItem repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Item); LinkButton lnk = new LinkButton(); lnk.ID = "lnk_itemname"; lnk.Text = String.Format("{0}",(dt.Tables[0].Rows[repeatItem.ItemIndex]["itemname"])); lnk.Click += new System.EventHandler(link_Click); repeatItem.Controls.Add(lnk); // Add SeparatorTemplate Dynamically repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Separator); LiteralControl ltrlHR = new LiteralControl(); ltrlHR.Text = "<hr />"; repeatItem.Controls.Add(ltrlHR); } // Add Repeater Control as Child Control // of Panel Control Panel1.Controls.Add(Repeater1); } protected void link_Click(object sender, EventArgs e) { cnn.ConnectionString = ConfigurationManager.ConnectionStrings["jin"].ConnectionString; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand("str_get_subitemDetails", cnn); da.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); DataTable dt = new DataTable("submenu"); da.Fill(dt); Session["subitem_name"] = dt.Rows[0]["subitem_name"].ToString(); Session["item_descript"] = dt.Rows[0]["item_descript"].ToString(); Session["item_rate"] = dt.Rows[0]["item_rate"].ToString(); Response.Redirect("getsubitem.aspx"); } }我的StoredProcedure代码如下:
My StoredProcedure Code is this:
USE [JIN] GO /****** Object: StoredProcedure [dbo].[str_get_subitemDetails] Script Date: 03/06/2013 16:51:55 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[str_get_subitemDetails] @item_id nvarchar(50), @itemname nvarchar(50), @subitem_name nvarchar(50), @item_descript nvarchar(100), @item_rate decimal(18,2) as begin select submenu.subitem_name,submenu.item_descript,submenu.item_rate from submenu join menu on menu.item_id=submenu.item_id where menu.itemname=@itemname end我正面对此错误... 否映射存在于对象类型ASP.dynamic_link_aspx到已知的托管提供者本机类型。 请帮助我 面对错误: 过程或函数''str_get_subitemDetails''需要参数''@item_id'',这是未提供的。 请帮助:
I m Facing this error... No mapping exists from object type ASP.dynamic_link_aspx to a known managed provider native type. Please Help me Facing error: Procedure or function ''str_get_subitemDetails'' expects parameter ''@item_id'', which was not supplied. please help:
推荐答案请检查如何向SqlCommand添加参数:SqlParameterCollection.AddWithValue [ ^ ]。 提示:您需要传递5个参数;) Please, check how to add parameters to SqlCommand: SqlParameterCollection.AddWithValue[^]. Hint: You need to pass 5 parameters ;)
更多推荐
动态链接按钮单击事件
发布评论