从标签到SQL数据源的数据绑定 [英] Bind data from label to SQL data source
问题描述
我想从标签数据绑定在 DataListControl
to SQL数据源,并认为这是 GridView控件
在其他页
I want to bind data from label in DataListControl
to SQL data source and view it as GridView
in other page.
我不知道如何从标签获取数据,并把它放在数据库...
I don't know how to get data from label and put it in database ...
我试图code这一点,但我需要的就是这样,的GetData code>从标签和投入的变量。
I tried to code this but what I need is the way to GetData
from label and put in to the variable.
我已经创建了:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class Products : System.Web.UI.Page
{
// string Name = Label.Equals(Namelable) // What should I do here to Get data from Lable?!
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOrder_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("sp_Order", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", Name);
}
}
任何想法做什么?
Any Idea what to do?
推荐答案
假设你的标签是一个 ASP:标签
cmd.Parameters.AddWithValue("@Name", YourLabel.Text);
如果你指的是从拉动标签的的DataList
需要的找到的控制例如第一
If you are referring to pulling a label from a DataList
you need to find the control first e.g.
var label = dataList.Items[i].FindControl("yourLabel") as Label;
cmd.Parameters.AddWithValue("@Name", label.Text);
仅供参考 - 这通常不是一个好主意,你的看法......
FYI - it's generally not a good idea to couple your data access layer with your view...
这篇关于从标签到SQL数据源的数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!