首页 > 编程 > .NET > 正文

一天精通asp.net的学习经验小结

2024-07-10 12:42:37
字体:
来源:转载
供稿:网友
1、Validator
2、IsPostBack
3、AutoPostBack。控件离开焦点的时候自动Post。
4、repeater控件的使用。:Repeater控件比以前版本的asp.net好用了,只要 Eval就可以了,不用DataBinder.Eval(container.DataItem,"***"):了,只要Eval("Name")就可以,注意不能丢了前面的“#”。
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
嘎嘎嘎
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Name")%>
<%# Eval("Desc")%>
</ItemTemplate>
</asp:Repeater>

protected void Button3_Click(object sender, EventArgs e)
{
List<Person> list = new List<Person>();
list.Add(new Person(){Name="芭芭拉",Desc="白牙呗"});
list.Add(new Person(){Name="奥巴马",Desc="黑黝黑"});
Repeater1.DataSource = list;
Repeater1.DataBind();
}
5、DataList控件:
(1)行的高亮选中
<asp:DataList ID="DataList1" runat="server" >
<SelectedItemStyle BackColor="#FF6666" />
<ItemTemplate>
<%# Eval("Name")%>
<%# Eval("Desc")%>
<asp:LinkButton ID="LinkButton1" runat="server" Text="选择" CommandName="select" />
</ItemTemplate>
</asp:DataList>
核心是CommandName这个属性,可选值还有edit、delete等可选值,当按钮被点击的时候将会执行EditCommand、DeleteCommand等事件。
(2)行的在位编辑:
<asp:DataList ID="DataList1" runat="server"
oneditcommand="DataList1_EditCommand">
<SelectedItemStyle BackColor="#FF6666" />
<EditItemTemplate>
<asp:TextBox runat="server" ID="t1" Text='<%# Eval("Name")%>' />
<asp:TextBox runat="server" ID="t2" Text='<%# Eval("Desc")%>' />
<asp:Button runat="server" Text="提交" CommandName="update" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("Name")%>
<%# Eval("Desc")%>
<asp:LinkButton ID="LinkButton1" runat="server" Text="编辑" CommandName="edit" />
</ItemTemplate>
</asp:DataList>

protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
ReBind();
}

private void ReBind()
{
List<Person> list = new List<Person>();
list.Add(new Person() { Name = "芭芭拉", Desc = "白牙呗" });
list.Add(new Person() { Name = "奥巴马", Desc = "黑黝黑" });
Repeater1.DataSource = list;
Repeater1.DataBind();

DataList1.DataSource = list;
DataList1.DataBind();
}
(3)行的在位编辑并且提交修改
<asp:DataList ID="DataList1" runat="server"
oneditcommand="DataList1_EditCommand"
onupdatecommand="DataList1_UpdateCommand">
<SelectedItemStyle BackColor="#FF6666" />
<EditItemTemplate>
<asp:TextBox runat="server" ID="t1" Text='<%# Eval("Name")%>' />
<asp:TextBox runat="server" ID="t2" Text='<%# Eval("Desc")%>' />
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表