<%#Eval()%> 单向绑定(读取数据)
<%#Bind()%> 双向绑定(读、写数据)
ListView中ItemUpdating事件找控件:
DropDownList ddlLinkType = (DropDownList)ListView1.Items[e.ItemIndex].FindControl
("DropDownList");
ListView中ItemDataBound、ItemInserting事件找控件:
DropDownList ddlLinkType = (DropDownList)e.Item.FindControl("ddlLinkType");
ListView命令行操作:
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
int index = ((ListViewDataItem)e.Item).DisplayIndex;//获取当前行的行号
Int64 id = (Int64)ListView1.DataKeys[index].Value;//取当前操作行的主键值
if (e.CommandName == "incAge")
{
T_PersonsTableAdapter adapter = new T_PersonsTableAdapter();
adapter.incAge(id);
ListView1.DataBind();
}
}
ListView的行按钮和Repeater一样,不同的是取当前行数据的方式.
int index = ((ListViewDataItem)e.Item).DisplayIndex;//获取当前行的行号
Int64 id = (Int64)ListView1.DataKeys[index].Value;//取当前操作行的主键值
如果对数据进行了操作,最后要对ListView执行DataBind刷新数据.由ListView的DataKeyNames属性决
定存储哪些字段值为主键,可以多个主键(和数据库主键没有直接关系),所以有Values.
排序:将LayoutTemplate中的表头用<asp:LinkButton runat="server" CommandName="Sort"
Text="ID" CommandArgument="ID" />代替,其中CommandArgument的值为排序字段.只要是
CommandName、CommandArgument对就行,展现成什么、显示在哪儿都可以.