<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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" Width="100%" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical"
onselectedindexchanged="DataList1_SelectedIndexChanged"
OnCancelCommand="DataList1_CancelCommand" OnEditCommand="DataList1_EditCommand"
OnUpdateCommand="DataList1_UpdateCommand" style="margin-top: 0px" >
<FooterStyle BackColor="#CCCC99" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#F7F7DE" />
<EditItemTemplate>
<table style="width:100%;">
<tr>
<td width="30%">
<asp:TextBox ID="TextBox1" runat="server" Width="100%"
Text='<%# Eval("pcode") %>'></asp:TextBox>
</td>
<td width="30%">
<asp:TextBox ID="TextBox2" runat="server" Width="100%"
Text='<%# Eval("ItemNAME") %>'></asp:TextBox>
</td>
<td width="40%">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="update">更新</asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate>
<SelectedItemStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<table style="width:100%;">
<tr>
<td width="30%">
<%# Eval("pcode")%> </td>
<td width="30%">
<%# Eval("ItemNAME")%> </td>
<td width="40%">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="edit">编辑</asp:LinkButton><asp:LinkButton
ID="LinkButton2" runat="server" CommandName="cancel"
>取消</asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Blwy BarCodeConnectionString %>"
SelectCommand="SELECT [pcode], [ItemNAME] FROM [CODE_Pcode_create ] WHERE ([OrderNo] = @OrderNo)">
<SelectParameters>
<asp:Parameter DefaultValue="1001A012-1/1" Name="OrderNo" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>using System;
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;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{ }
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
Response.Write(((TextBox)(e.Item.FindControl("TextBox1"))).Text);
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
Response.Write("<script language='javascript'>((TextBox)(e.Item.FindControl('TextBox1'))).Text</script>);
}
}
总是提示这行(TextBox)(e.Item.FindControl('TextBox1')错误, 未将对象的引用设置到对象的实例。
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" Width="100%" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical"
onselectedindexchanged="DataList1_SelectedIndexChanged"
OnCancelCommand="DataList1_CancelCommand" OnEditCommand="DataList1_EditCommand"
OnUpdateCommand="DataList1_UpdateCommand" style="margin-top: 0px" >
<FooterStyle BackColor="#CCCC99" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#F7F7DE" />
<EditItemTemplate>
<table style="width:100%;">
<tr>
<td width="30%">
<asp:TextBox ID="TextBox1" runat="server" Width="100%"
Text='<%# Eval("pcode") %>'></asp:TextBox>
</td>
<td width="30%">
<asp:TextBox ID="TextBox2" runat="server" Width="100%"
Text='<%# Eval("ItemNAME") %>'></asp:TextBox>
</td>
<td width="40%">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="update">更新</asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate>
<SelectedItemStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<table style="width:100%;">
<tr>
<td width="30%">
<%# Eval("pcode")%> </td>
<td width="30%">
<%# Eval("ItemNAME")%> </td>
<td width="40%">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="edit">编辑</asp:LinkButton><asp:LinkButton
ID="LinkButton2" runat="server" CommandName="cancel"
>取消</asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Blwy BarCodeConnectionString %>"
SelectCommand="SELECT [pcode], [ItemNAME] FROM [CODE_Pcode_create ] WHERE ([OrderNo] = @OrderNo)">
<SelectParameters>
<asp:Parameter DefaultValue="1001A012-1/1" Name="OrderNo" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>using System;
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;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{ }
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
Response.Write(((TextBox)(e.Item.FindControl("TextBox1"))).Text);
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
Response.Write("<script language='javascript'>((TextBox)(e.Item.FindControl('TextBox1'))).Text</script>);
}
}
总是提示这行(TextBox)(e.Item.FindControl('TextBox1')错误, 未将对象的引用设置到对象的实例。
解决方案 »
- sandy c#中不知道数组的类型能不能遍历?Hashtable ht = new Hashtable();
- 做了数据绑定,GridView中<EmptyDataTemplate>还是没起作用
- 这和SQL2005有什么关系啊
- 谁用过ChangePassword控件可以请教一些问题吗?
- asp.net Calendar1 怎么只显示当前月份的30天。
- 如何得到repeater控件中自动生成的控件的ID?急!!!!!!
- 急求C#做的网络视频播放器,在线等待,帮帮我吧,高手!
- ASP.NET多线程问题
- cssl
- Ajax客户端框架未加载
- 一个简单的JS问题
- IIS外部请求在大负载的情况下进不来,本机访问却正常
LZ依赖性有点强哦至于你说的(TextBox)(e.Item.FindControl('TextBox1')为null
说明找不到textbox这个控件,试着e.Item.FindControl别的控件试试
===========================
找不到是因为EditItemTemplate 里面有2个TextBox
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{ string text= ((TextBox)e.Item.FindControl("TextBox1")).Text;
}得不到编辑后的数据,取到的还是原来