日期:2011-08-19 浏览次数:20532 次
1、绑定在DataList中的DropDownList
private void dlistOrder_EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
//绑定订单状态
for(int i=0;i<((DropDownList)dlistOrder.Items[e.Item.ItemIndex].FindControl("ddlFlag")).Items.Count;i++)
{
if(((DropDownList)dlistOrder.Items[e.Item.ItemIndex].FindControl("ddlFlag")).Items[i].Value == dv.Table.Rows[0]["OrStatus"].ToString())
{
((DropDownList)dlistOrder.Items[e.Item.ItemIndex].FindControl("ddlFlag")).Items[i].Selected = true;
}
}
}
2、另一种绑定方式
//绑定送货方式
DataView shipType = OrderSO.GetShipTypeList();
DropDownList ddlShipType = (DropDownList)dlistOrder.Items[e.Item.ItemIndex].FindControl("ddlShipType");
ddlShipType.DataSource = shipType;
ddlShipType.DataTextField = "StName";
ddlShipType.DataValueField = "StId";
ddlShipType.DataBind();
ddlShipType.SelectedIndex = ddlShipType.Items.IndexOf(ddlShipType.Items.FindByValue(dv.Table.Rows[0]["OrShipType"].ToString()));
3、在编辑嵌套在Datalist内的Datagrid某条记录时定位它所在的Datalist行
protected void MyList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HtmlInputHidden odid = (HtmlInputHidden) e.Item.Cells[0].FindControl("odid");
DataListItem item = (DataListItem)e.Item.Parent.Parent.Parent;
DropDownList flag = (DropDownList)item.FindControl("ddlFlag");
if(flag.SelectedIndex == 0)
{
if(e.CommandName == "Delete")
{
int iOdId = Convert.ToInt32(odid.Value);
//删除订单明细方法
OrderSO.DeleteOrderDetail(iOdId);
}
}
else
{
GDCIC.Framework.Utility.MessageBox(this,"modifyError","经过确认的订单不能再修改!!");
return;
}
dlistOrder.EditItemIndex = -1;
BindData();
}
}
4、DataBinding绑定表达式:
1) 普通的绑定表达式
<%# DataBinder.Eval(Container.DataItem, "ContactName") %>
2) 文本+绑定表达式
<asp:Label id=lblDate runat="server" Text='<%# "[" + DataBinder.Eval(Container, "DataItem.NewsCreatedate") + "]" %>' ForeColor="Red"></asp:Label>
3) 同时带有显示格式的绑定表达式
<%# DataBinder.Eval(Container,"DataItem.USActiveDate","{0:yyyy-MM-dd}") %>
4) 结合绑定表达式和模态框
<A href='<%# ShowModalWin(Convert.ToString(DataBinder.Eval(Container.DataItem, "PictureImage")),Convert.ToString(DataBinder.Eval(Container.DataItem, "DetailID")),Convert.ToString(DataBinder.Eval(Container.DataItem, "PictureID")))%>'>
其中:后台代码文件中ShowModalWin()方法的定义如下:
protected string ShowModalWin(string PictureImage,string DetailID,string PictureID)
{
return " window.showModalDialog(\"Customers/ShowPictureInfo.aspx?pid="+PictureImage+"&did="+DetailID+"&id="+PictureID+"\",\"\",\"dialogHeight:320px;dialogWidth:480px;center:yes;help:no;status:no;scroll:no\");";
}
或者将参数提取出来