0
我的數據列表項工作的編輯理念,我覺得我做了所有的代碼正確的,但如果點擊編輯按鈕空白頁面上展示,請參閱這個問題,併發出任何錯誤和拯救建議,請datalist編輯不起作用?
HTML代碼
<asp:DataList ID="DataList1" runat="server" DataKeyField="outlet_id" OnEditCommand="DataList1_EditCommand" OnCancelCommand="DataList1_CancelCommand" RepeatColumns="2">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("outlet_id") %>' ></asp:Label>
<asp:Label ID="lbl" runat="server" Text='<%#Eval("company_name") %>' ></asp:Label>
<asp:Button ID="edit" runat="server" Text="Edit" CommandName="edit" />
<asp:Button ID="delete" runat="server" Text="Del" CommandName="del" />
</ItemTemplate>
<EditItemTemplate>
id<asp:TextBox ID="id" runat="server" Text='<%#Eval("outlet_id") %>'></asp:TextBox>
name<asp:TextBox ID="name" runat="server" Text='<%#Eval("company_name") %>' ></asp:TextBox>
<asp:Button ID="Button2" runat="server" CommandName="update" Text="update" />
<asp:Button ID="Button3" runat="server" CommandName="cancel" Text="Cancel" />
</EditItemTemplate>
</asp:DataList>
</form>
</body>
和C#代碼在這裏波紋管
頁面加載
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
編輯命令代碼
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
}
取消命令代碼
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = -1;
DataList1.DataBind();
}
這是數據列表結合
protected void bind()
{
SqlConnection con = new SqlConnection(strconnection);
con.Open();
string qry = "select top 10 outlet_id,company_name from outlet_table ";
SqlDataAdapter Da = new SqlDataAdapter(qry, con);
DataSet ds = new DataSet();
Da.Fill(ds, "outlet");
DataList1.DataSource = ds;
DataList1.DataBind();
}
這是點擊編輯按鈕之後顯示客戶機側的html數據
<body>
<form name="form1" method="post" action="Demo.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="zVlNF4jkNpf9ZmIBtYaHSdSPa9l8zKVA4H0JXxnhqVytzfrbVWUuOuY8004hXYRY8KuBKqPKgV3kS4RQBegrJQ5LErL3VdV9TeluNoxAZLtDu0/62xR8Ij/jD638pPKb">
</div>
<div>
<input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="">
</div>
</form>
</body>
您調用未定義的方法。 – 2015-09-16 08:31:53