asp.net datalist中有一个标签有一个命令按钮 怎么实现单击命令按钮把标签的TEXT差入到SQl数据表中(C#)
3个回答
展开全部
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标尺耐题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="Id"
oneditcommand="DataList1_EditCommand"
oncancelcommand="DataList1_CancelCommand"
onupdatecommand="DataList1_UpdateCommand">
<ItemTemplate>
<asp:LinkButton ID="肢高LinkButton1" runat="server" CommandName="edit">编辑</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="update">保存<历困尺/asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="cancel">取消</asp:LinkButton>
</EditItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
程序代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex = e.Item.ItemIndex;//显示编辑列
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string id = this.DataList1.DataKeys[e.Item.ItemIndex].ToString();//获取datakeys的值(id)
string info = ((TextBox)e.Item.FindControl("TextBox1")).Text;//获取textbox的值
}
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex = -1;//取消显示的编辑列
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标尺耐题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="Id"
oneditcommand="DataList1_EditCommand"
oncancelcommand="DataList1_CancelCommand"
onupdatecommand="DataList1_UpdateCommand">
<ItemTemplate>
<asp:LinkButton ID="肢高LinkButton1" runat="server" CommandName="edit">编辑</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="update">保存<历困尺/asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="cancel">取消</asp:LinkButton>
</EditItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
程序代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex = e.Item.ItemIndex;//显示编辑列
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string id = this.DataList1.DataKeys[e.Item.ItemIndex].ToString();//获取datakeys的值(id)
string info = ((TextBox)e.Item.FindControl("TextBox1")).Text;//获取textbox的值
}
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex = -1;//取消显示的编辑列
}
}
}
展开全部
datalist属性中有个事件清隐裂叫ItemCommand双击他,可携简以进入后台编写代码,用e.commandargument
传递参答闭数,就可以了
传递参答闭数,就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建意楼主去看到ADO.net
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询