protected void Page_Load(object sender, EventArgs e)
{
OpenFileLogic logic = new OpenFileLogic();
DeliverySheetDetail deliverySheet = null;
if(filename == OpenFileCommonCode.CREATED_FROM_BILL)
{
deliverySheet = logic.getBillFile_DeliveryEdit(code);
TbCreateDate.Text = deliverySheet.CreateDate;
TbTitle.Text = deliverySheet.Title;
TbSpecialNote.Text = deliverySheet.SpecialNote;
GridDeliverablesSheets.DataSource = deliverySheet.WorkDetails;
GridDeliverablesSheets.DataBind();
}
}
protected void GridDeliverablesSheets_RowDataBound(object sender, GridViewRowEventArgs e)
{
OpenFileLogic logic =new OpenFileLogic();
if(e.Row.RowType ==DataControlRowType.DataRow )
{
DropDownList ddlNumberUnit = (DropDownList) e.Row.FindControl("DdlNumberUnit") ;
ddlNumberUnit.DataSource = logic.getNumberUnitData();
ddlNumberUnit.DataTextField = "Name";
ddlNumberUnit.DataValueField = "Code";
ddlNumberUnit.DataBind();
}
}
public List<NumberUnit> getNumberUnitData()
{
List<NumberUnit> nUnit = new List<NumberUnit>();
using (DBAccess dbaccess = new DBAccess())
{
dbaccess.OpenConnection();
nUnit = dbaccess.GetNumberUnit();
}
return nUnit;
}
<ItemTemplate>
<asp:TextBox style="text-align:right" ID="TbQuantity" Width="40px" runat="server" Text='<%# Bind("Quantity") %>' />
<asp:DropDownList ID="DdlNumberUnit" runat="server">
</asp:DropDownList>
</ItemTemplate>
在这段代码中,我显示了DropDown列表值,我从getNumberUnitData()方法获取了这些值。但是,当我想将特定数据加载到gridview时,我无法做到这一点。在Page_Load方法中,delivery.WorkDetails包含我想在DropDown列表中显示的“Data”对象。
答案 0 :(得分:1)
我想也许你需要添加POSTBACK
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack) {
// First time to run your code
}
}
答案 1 :(得分:0)
object NumberUnitData = DataBinder.Eval(e.Row.DataItem, "Data");
if (NumberUnitData == null)
{
ddlNumberUnit.SelectedItem.Text = "";
}
else
{
ddlNumberUnit.SelectedItem.Text = NumberUnitData.ToString();
}
我在ddlNumberUnit.DataBind()下面添加了这段代码;它奏效了。