<wijmo:C1GridView ID="gvGoodsList" runat="server" AllowClientEditing="true"
ScrollMode="Auto" Height="250px" AutoGenerateColumns="false" OnClientAfterCellEdit="gvGoodsList_AfertCellEdit"
OnEndRowUpdated="gvGoodsList_EndRowUpdated" OnRowUpdating="gvGoodsList_RowUpdating"
OnClientBeforeCellEdit = "beforeCellEdit"
OnClientBeforeCellUpdate = "beforeCellUpdate" s
ShowFooter="true" ShowRowHeader="false" AllowColMoving="false" DataKeyNames="pr_batch_no"
Width="99%" LoadingText="载入中..." onrowdatabound="gvGoodsList_RowDataBound" >
<Columns>
<wijmo:C1TemplateField HeaderText="选择" Width="60px" AllowSizing="False">
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</wijmo:C1TemplateField>
<wijmo:C1TemplateField HeaderText="序号" Width="60px" >
<ItemTemplate>
<%#Container.DataItemIndex + 1 %>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</wijmo:C1TemplateField>
<wijmo:C1BoundField DataField="goods_no" HeaderText="商品编码" ReadOnly="true" Width="100px"/>
<wijmo:C1BoundField DataField="goods_name" HeaderText="商品名称" ReadOnly="true" Width="150px"/>
<wijmo:C1BoundField DataField="supplier_name" HeaderText="供应商" Width="120px"/>
<wijmo:C1BoundField DataField="unit" HeaderText="单位" ReadOnly="true" Width="80px">
<ItemStyle HorizontalAlign="Center"/>
</wijmo:C1BoundField>
<wijmo:C1BoundField DataField="qty" HeaderText="数量" Width="80px">
<ItemStyle CssClass="C1RBox"/>
</wijmo:C1BoundField>
<wijmo:C1BoundField DataField="vendor_price" HeaderText="采购价" Width="80px" >
<ItemStyle CssClass="C1RBox"/>
</wijmo:C1BoundField>
<wijmo:C1BoundField DataField="amount" HeaderText="采购金额" ReadOnly="true" Width="80px"/>
<wijmo:C1BoundField DataField="remark" HeaderText="备注" Width="120px">
<ItemStyle CssClass="C1NBox" />
</wijmo:C1BoundField>
</Columns>
</wijmo:C1GridView>
function beforeCellEdit(e, args) {
if (args.cell.column().dataField === "supplier_name") {
var data = $("#gvGoodsList").c1gridview("data");
var goods_no = data[args.cell._ri][2];
var session_key = document.getElementById("hfSessionKey").value;
var testArray;
strData = "{'goods_no':'" + goods_no + "','session_key':'" + session_key + "'}",
$.ajax({
type: "OST",
url: "StoreApply_Edit.aspx/GetGoodsVendorList",
data: strData,
contentType: "application/json; charset=utf-8",
async: false,
success: function (data) {
var json = eval(data);
testArray = eval(json.d);
}
})
$("<input />")
.width("100%")
.appendTo(args.cell.container().empty())
.wijcombobox({
data: testArray,
showTrigger: true
});
args.handled = true;
}
}
function beforeCellUpdate(e, args) {
if (args.cell.column().dataField === "supplier_name") {
args.value = args.cell.container()
.find("input")
.wijcombobox("option", "text");
document.getElementById("hfVendorNo").value = args.cell.container()
.find("input")
.wijcombobox("option", "selectedValue");
}
}
function gvGoodsList_AfertCellEdit(e, args) {
if (args.cell.column().dataField === "supplier_name") {
args.cell.container()
.find("input")
.wijcombobox("destroy");
}
item_update();
}
function item_update() {
var grid = $("#gvGoodsList");
if (grid != null) {
grid.c1gridview("endEdit");
grid.c1gridview("update");
}
}
后台:
protected void gvGoodsList_RowUpdating(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewUpdateEventArgs e)
{
DataTable dtList = Session[this.GetCurPageGuid()] as DataTable;
DataRow row = dtList.Rows.Find(gvGoodsList.DataKeys[e.RowIndex].Value);
if (row != null)
{
foreach (DictionaryEntry entry in e.NewValues)
{
if (entry.Key.ToString() == "supplier_name")
{
if (hfVendorNo.Value == "null")
{
row["is_raw"] = "1";
row[(string)entry.Key] = "";
row["supplier_no"] = "";
}
else
{
row["is_raw"] = "0";
row[(string)entry.Key] = entry.Value;
row["supplier_no"] = hfVendorNo.Value;
string goods_no = row["goods_no"].ToString();
DataTable dtTemp = (DataTable)Session[hfSessionKey.Value];
DataRow[] drs = dtTemp.Select("goods_no='" + goods_no + "' and supplierno='" + hfVendorNo.Value + "'");
if (drs.Length > 0)
row["in_price"] = drs[0]["in_price"];
}
}
else
{
row[(string)entry.Key] = entry.Value;
}
}
}
else
{
throw new RowNotInTableException();
}
Session[this.GetCurPageGuid()] = dtList;
}
protected void gvGoodsList_EndRowUpdated(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewEndRowUpdatedEventArgs e)
{
ReBindList();
}
protected void gvGoodsList_RowDataBound(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewRowEventArgs e)
{
if (e.Row.RowType == C1.Web.Wijmo.Controls.C1GridView.C1GridViewRowType.DataRow)
{
if (e.Row.Cells[3].Text == "&nbsp;")
{
e.Row.Cells[3].BackColor = Color.Red;
e.Row.Cells[3].ToolTip = "商品信息不存在,请维护";
}
}
} |
|