从标签到SQL数据源的数据绑定

编程入门 行业动态 更新时间:2024-10-22 07:48:48
本文介绍了从标签到SQL数据源的数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从标签数据绑定在 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 从标签和投入的变量。

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数据源的数据绑定

本文发布于:2023-10-27 23:09:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534807.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   绑定   标签   数据   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!