|
|
|
ขออนุญาติถามเรื่อง GridView นิ๊สนึงนะครับค่อยข้างยากหน่อยนะครับ |
|
|
|
|
|
|
|
จากรูปหากผมต้องการให้รายการใดก็ตามที่ สถานะสินค้า เป็น "ส่งของครบถ้วน"
ข้อความ Edit แล้ว Delete หายไปเฉพาะรายการนั้นมีความเป็นไปได้ไหมครับ
Code (C#)
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="C#" Debug="true" EnableEventValidation="true" %>
<script runat="server">
SqlConnection objConn;
SqlCommand objCmd;
String strSQL;
public void Page_Load(object sender, EventArgs e)
{
if (Session["strUser"]==null) {
Response.Redirect("LoginAdmin.aspx");
Response.End();
} else {
this.lblStatus.Text = "Welcome [" + Session["strUser"] + "]";
String strConnString;
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=cartoon;Max Pool Size=400;Connect Timeout=6000;";
objConn = new SqlConnection(strConnString);
objConn.Open();
if (!Page.IsPostBack)
{
ViewData();
BindData();
}
}
}
void Page_UnLoad()
{
objConn.Close();
objConn = null;
}
void BindData()
{
String strSQL;
// strSQL = "SELECT CusOrderID,CusOrderDetailID,SetProductID,(Select s.SetProductName from SetProduct as s where s.SetProductID = c.SetProductID)as SetProductName,Quantity,OrderDetailPrice,StockChk FROM CusOrderDetail as c where CusOrderID = '" + Request.QueryString["CusOrderID"] + "'";
strSQL = "SELECT PurchaseOrderID,PurchaseOrderDetailID,ProductID,(Select s.ProductName from Product as s where s.ProductID = c.ProductID)as ProductName,OrderQuantity,ProductPrice,ReceiveQuantity,PStockChk,DiffQuantity FROM PurchaseOrderDetail as c where PurchaseOrderID = '" + Request.QueryString["PurchaseOrderID"] + "'";
SqlDataReader dtReader;
objCmd = new SqlCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
//*** BindData to GridView ***//
myGridView.DataSource = dtReader;
myGridView.DataBind();
dtReader.Close();
dtReader = null;
}
public DataTable DataTableProduct()
{
String strConnString = null;
SqlDataAdapter dtAdapter = new SqlDataAdapter();
DataTable dt = new DataTable();
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=cartoon;Max Pool Size=400;Connect Timeout=6000;";
objConn = new SqlConnection(strConnString);
objConn.Open();
string strSQL = null;
strSQL = "SELECT * FROM Product";
dtAdapter = new SqlDataAdapter(strSQL, objConn);
dtAdapter.Fill(dt);
dtAdapter = null;
return dt;
Response.Redirect("page5-2-1.aspx");
Response.End();
}
void ViewData()
{
//*** DataTable ***//
SqlDataAdapter dtAdapter;
DataTable dt = new DataTable();
strSQL = "select (select COUNT(pd.PurchaseOrderID)From PurchaseOrderDetail as pd where pd.PurchaseOrderID = po.PurchaseOrderID) as myCount,(select SUM(pd.ProductPrice)from PurchaseOrderDetail as pd where pd.PurchaseOrderID = po.PurchaseOrderID)as mySum FROM PurchaseOrder as po where PurchaseOrderID ='" + Request.QueryString["PurchaseOrderID"] + "'";
// Response.Write(strSQL);
dtAdapter = new SqlDataAdapter(strSQL, objConn);
dtAdapter.Fill(dt);
if (dt.Rows.Count > 0)
{
this.lblmyCount.Text = (string)dt.Rows[0]["myCount"].ToString();
this.lblmySum.Text = (string)dt.Rows[0]["mySum"].ToString();
}
}
/*DropDownListDataTable()
{
SqlConnection objConn;
SqlDataAdapter dtAdapter;
DataTable dt = new DataTable();
String strConnString;
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=cartoon;Max Pool Size=400;Connect Timeout=6000;";
objConn = new SqlConnection(strConnString);
objConn.Open();
String strSQL;
strSQL = "SELECT SetProductName FROM SetProduct ";
dtAdapter = new SqlDataAdapter(strSQL, objConn);
dtAdapter.Fill(dt);
dtAdapter = null;
objConn.Close();
objConn = null;
//*** DropDownList **
this.txtAddProductID.DataSource = dt;
this.txtAddProductID.DataTextField = "SetProductName";
this.txtAddProductID.DataValueField = "SetProductName";
this.txtAddProductID.DataBind();
//*** Default Value ***
//myDDL1.SelectedIndex = myDDL1.Items.IndexOf(myDDL1.Items.FindByValue("dadada")); //*** By DataValueField ***
//myDDL1.SelectedIndex = myDDL1.Items.IndexOf(myDDL1.Items.FindByText("Thailand")); //*** By DataTextField **
}*/
void modEditCommand(Object sender, GridViewEditEventArgs e)
{
myGridView.EditIndex = e.NewEditIndex;
myGridView.ShowFooter = false;
BindData();
ViewData();
}
void modCancelCommand(Object sender, GridViewCancelEditEventArgs e)
{
myGridView.EditIndex = -1;
myGridView.ShowFooter = true;
BindData();
ViewData();
}
void modDeleteCommand(Object sender, GridViewDeleteEventArgs e)
{
strSQL = "DELETE FROM PurchaseOrderDetail WHERE PurchaseOrderDetailID = '" + myGridView.DataKeys[e.RowIndex].Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
Response.Write("ลบใบสั่งรหัส " + myGridView.DataKeys[e.RowIndex].Value + " เรียบร้อยแล้ว");
myGridView.EditIndex = -1;
BindData();
ViewData();
}
void myGridView_RowCommand(Object source, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Add")
{
//*** PurchaseOrderID ***//
TextBox txtPurchaseOrderID = (TextBox)myGridView.FooterRow.FindControl("txtAddPurchaseOrderID");
//*** PurchaseOrderDetailID ***//
TextBox txtPurchaseOrderDetailID = (TextBox)myGridView.FooterRow.FindControl("txtAddPurchaseOrderDetailID");
//*** ProductID ***//
DropDownList txtProductID = (DropDownList)myGridView.FooterRow.FindControl("txtAddProductID");
//*** OrderQuantity ***//
TextBox txtOrderQuantity = (TextBox)myGridView.FooterRow.FindControl("txtAddOrderQuantity");
//*** ReceiveQuantity ***//
TextBox txtReceiveQuantity = (TextBox)myGridView.FooterRow.FindControl("txtAddReceiveQuantity");
//*** ProductPrice ***//
TextBox txtProductPrice = (TextBox)myGridView.FooterRow.FindControl("txtAddProductPrice");
//*** PStockChk ***//
DropDownList txtPStockChk = (DropDownList)myGridView.FooterRow.FindControl("txtAddPStockChk");
strSQL = "INSERT INTO PurchaseOrderDetail (PurchaseOrderID,ProductID,OrderQuantity,ReceiveQuantity,DiffQuantity,ProductPrice,PStockChk) " + " VALUES ('" + txtPurchaseOrderID.Text + "','" +txtProductID.SelectedItem.Value + "','" + txtOrderQuantity.Text + "','0','" + txtOrderQuantity.Text + "','" + txtProductPrice.Text + "','" + txtPStockChk.Text + "')";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
Response.Write("เพิ่มใบสั่งซื้อเรียบร้อยแล้ว");
BindData();
ViewData();
}
} catch (Exception ex) {
Response.Write("โปรดตรวจสอบข้อมูล " +ex.Message + " ให้ถูกต้อง");}
}
void modUpdateCommand(Object sender, GridViewUpdateEventArgs e)
{
//try
// {
//*** PurchaseOrderDetailID ***//
TextBox txtPurchaseOrderDetailID = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditPurchaseOrderDetailID");
//*** ProductID***//
DropDownList txtProductID = (DropDownList)myGridView.Rows[e.RowIndex].FindControl("txtEditProductID");
//*** PurchaseOrderID ***//
TextBox txtPurchaseOrderID = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditPurchaseOrderID");
//*** OrderQuantity ***//
TextBox txtOrderQuantity = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditOrderQuantity");
//*** ReceiveQuantity ***//
TextBox txtReceiveQuantity = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditReceiveQuantity");
//*** ProductPrice ***//
TextBox txtProductPrice = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditProductPrice");
//*** PStockChk ***//
DropDownList txtPStockChk = (DropDownList)myGridView.Rows[e.RowIndex].FindControl("txtEditPStockChk");
/*** ReceiveQuantity ***/
Label txtDiffQuantity = (Label)myGridView.Rows[e.RowIndex].FindControl("txtEditDiffQuantity");
//********************ดึงค่าจากเบสมาเทียบว่าจำนวนที่ใส่เกินที่สั่งหรือไม่***********
//Response.Write(txtQuantity.Text);// จำนวน string
string SetQuautity1 = (txtReceiveQuantity.Text); //ที่กรอกเข้าไป
int Quantity1 = Convert.ToInt32(SetQuautity1);// convert to int
string SetQuautity2 = (txtOrderQuantity.Text); //จำนวนที่สั่งซื้อ
int Quantity2 = Convert.ToInt32(SetQuautity2);// convert to int
if (Quantity1 > Quantity2)
{
this.Label2.Text = ("จำนวนที่ใส่ผิดพลาด" + "สินค้าที่สั่งซือคือ " + Quantity2 + " ชิ้น");
//Response.Write("สินค้าจำนวนไม่เพียงพอ"+"สินค้าที่มีในสต๊อกคือ "+Quantity2+"ชิ้น");
}
else
{
//ครั้งแรกของครบ สั่ง10ส่ง10
if ((txtOrderQuantity.Text == txtReceiveQuantity.Text) && (txtPStockChk.Text == "ส่งของครบถ้วน"))//จำนวนสั่งเทียบรับเท่า และ เลือกส่งครบถ้วน
{
//แก้ไขราคา product
strSQL = "UPDATE PurchaseOrderDetail SET ProductPrice = " + txtProductPrice.Text + " where PurchaseOrderDetailID = '" + myGridView.DataKeys[e.RowIndex].Value + "'";
Response.Write(strSQL);
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//เพิ่มจำนวนลง product
strSQL = "UPDATE Product SET Quantity = Quantity+'" + txtReceiveQuantity.Text + "' where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//อัพเดทPurDetail
strSQL = "UPDATE PurchaseOrderDetail SET ReceiveQuantity='" + txtReceiveQuantity.Text + "',PStockChk='" + txtPStockChk.Text + "' where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//DiffQuantity ส่วนต่าง
strSQL = "UPDATE PurchaseOrderDetail SET DiffQuantity = '0' where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
Response.Write("เพิ่ม " + txtProductID.SelectedItem.Value + "จำนวน" + txtReceiveQuantity.Text + " เรียบร้อยแล้ว");
}
//รับแล้วของขาด สั่ง 10 ได้ 9
else if ((txtOrderQuantity.Text != txtReceiveQuantity.Text) && (txtPStockChk.Text == "ส่งสินค้าไม่ครบ"))//จำนวนสั่งเทียบรับไม่เท่า และ เป็นของที่ส่งไม่ครบ และ เลือกส่งครบถ้วน
{
//แก้ไขราคา product
strSQL = "UPDATE PurchaseOrderDetail SET ProductPrice = " + txtProductPrice.Text + " where PurchaseOrderDetailID = '" + myGridView.DataKeys[e.RowIndex].Value + "'";
Response.Write(strSQL);
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//เพิ่มจำนวนลง product (ไม่ครบเท่าที่สั่งนะ)
strSQL = "UPDATE Product SET Quantity = Quantity+'" + txtReceiveQuantity.Text + "' where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//อัพเดทPurDetail
strSQL = "UPDATE PurchaseOrderDetail SET ReceiveQuantity='" + txtReceiveQuantity.Text + "',PStockChk='" + txtPStockChk.Text + "' where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
// Response.Write("เพิ่ม " + txtProductID.SelectedItem.Value + "จำนวน" + txtReceiveQuantity.Text + " เรียบร้อยแล้ว");
//
strSQL = "UPDATE PurchaseOrderDetail SET DiffQuantity=0+" + txtOrderQuantity.Text + "-" + txtReceiveQuantity.Text + " where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
Response.Write("เพิ่ม " + txtProductID.SelectedItem.Value + "จำนวน" + txtReceiveQuantity.Text + " เรียบร้อยแล้ว");
}
//ครั้งสองของครบ
else if ((txtOrderQuantity.Text != txtReceiveQuantity.Text) && (txtPStockChk.Text == "ส่งของครบถ้วน") && (txtDiffQuantity.Text != "0"))//จำนวนสั่งเทียบรับเท่า และ เลือกส่งครบถ้วน และเช๊คอะไรซํกอย่าง
{
//แก้ไขราคา product
strSQL = "UPDATE PurchaseOrderDetail SET ProductPrice = " + txtProductPrice.Text + " where PurchaseOrderDetailID = '" + myGridView.DataKeys[e.RowIndex].Value + "'";
Response.Write(strSQL);
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//เพิ่มจำนวนลง product
strSQL = "UPDATE Product SET Quantity = Quantity+" + txtReceiveQuantity.Text + " where ProductID = '" + txtProductID.SelectedItem.Value + "'";
Response.Write(strSQL);
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
//อัพเดทPurDetail
strSQL = "UPDATE PurchaseOrderDetail SET ReceiveQuantity='" + txtOrderQuantity.Text + "',PStockChk='" + txtPStockChk.Text + "' where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
// Response.Write("เพิ่ม " + txtProductID.Text + "จำนวน" + txtReceiveQuantity.Text + " เรียบร้อยแล้ว");
//
strSQL = "UPDATE PurchaseOrderDetail SET DiffQuantity= 0 where ProductID = '" + txtProductID.SelectedItem.Value + "'";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
Response.Write("เพิ่มสินค้า " + txtProductID.Text + "จำนวน" + txtReceiveQuantity.Text + " เรียบร้อยแล้ว");
}
}
//}catch(Exception ex)
// {
// Response.Write(ex.Message+"Update");
// }
//
myGridView.EditIndex = -1;
myGridView.ShowFooter = true;
BindData();
ViewData();
}
void myGridView_RowDataBound(Object source, GridViewRowEventArgs e)
{
// Footer
if (e.Row.RowType == DataControlRowType.Footer) {
DropDownList txtProductID = (DropDownList)e.Row.FindControl("txtAddProductID");
if ((txtProductID != null))
{
txtProductID.DataSource = (DataTable)DataTableProduct();
txtProductID.DataTextField = "ProductName";
txtProductID.DataValueField = "ProductID";
txtProductID.DataBind();
}
}
//edit
if (e.Row.RowType == DataControlRowType.DataRow)
{
//*** PurchaseOrderID ***//
Label lblPurchaseOrderID = (Label)(e.Row.FindControl("lblPurchaseOrderID"));
if (lblPurchaseOrderID != null)
{
lblPurchaseOrderID.Text = DataBinder.Eval(e.Row.DataItem, "PurchaseOrderID").ToString();
}
//*** PurchaseOrderDetailID ***//
Label lblPurchaseOrderDetailID = (Label)(e.Row.FindControl("lblPurchaseOrderDetailID"));
if (lblPurchaseOrderDetailID != null)
{
lblPurchaseOrderDetailID.Text = DataBinder.Eval(e.Row.DataItem, "PurchaseOrderDetailID").ToString();
}
//*** ProductID ***//
DropDownList txtProductID = (DropDownList)(e.Row.FindControl("txtEditProductID"));
if ((txtProductID != null))
{
txtProductID.DataSource = (DataTable)DataTableProduct();
txtProductID.DataTextField = "ProductName";
txtProductID.DataValueField = "ProductID";
txtProductID.DataBind();
txtProductID.SelectedIndex = txtProductID.Items.IndexOf(txtProductID.Items.FindByValue((string)DataBinder.Eval(e.Row.DataItem, "ProductID")));
}
//*** ProductName***//
Label lblProductName = (Label)(e.Row.FindControl("lblProductName"));
if (lblProductName != null)
{
lblProductName.Text = DataBinder.Eval(e.Row.DataItem, "ProductName").ToString();
}
//*** OrderQuantity***//
Label lblOrderQuantity = (Label)(e.Row.FindControl("lblOrderQuantity"));
if (lblOrderQuantity != null)
{
lblOrderQuantity.Text = DataBinder.Eval(e.Row.DataItem, "OrderQuantity").ToString();
}
//*** ReceiveQuantity***//
Label lblReceiveQuantity = (Label)(e.Row.FindControl("lblReceiveQuantity"));
if (lblReceiveQuantity != null)
{
lblReceiveQuantity.Text = DataBinder.Eval(e.Row.DataItem, "ReceiveQuantity").ToString();
}
//*** DiffQuantity***//
Label lblDiffQuantity = (Label)(e.Row.FindControl("lblDiffQuantity"));
if (lblDiffQuantity != null)
{
lblDiffQuantity.Text = DataBinder.Eval(e.Row.DataItem, "DiffQuantity").ToString();
}
//*** ProductPrice***//
Label lblProductPrice = (Label)(e.Row.FindControl("lblProductPrice"));
if (lblProductPrice != null)
{
lblProductPrice.Text = DataBinder.Eval(e.Row.DataItem, "ProductPrice").ToString();
}
//*** lblPStockChk***//
Label lblPStockChk = (Label)(e.Row.FindControl("lblPStockChk"));
if (lblPStockChk != null)
{
lblPStockChk.Text = DataBinder.Eval(e.Row.DataItem, "PStockChk").ToString();
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.RadioButton1.Checked == true)
{
String strSQL;
strSQL = "UPDATE PurchaseOrder SET PaymentStatusType = 'รับสินค้าครบถ้วนแล้ว',PaymentAmount = (select SUM(pd.ProductPrice)from PurchaseOrderDetail as pd where pd.PurchaseOrderID = po.PurchaseOrderID) FROM PurchaseOrder as po where PurchaseOrderID = '" + Request.QueryString["PurchaseOrderID"] + "' ";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
lblstat.Text = "แก้ไขสถานะ รับสินค้าครบ เรียบร้อย";
}
if (this.RadioButton2.Checked == true)
{
String strSQL;
strSQL = "UPDATE PurchaseOrder SET PaymentStatusType = 'รอการจัดส่ง',PaymentAmount = (select SUM(pd.ProductPrice)from PurchaseOrderDetail as pd where pd.PurchaseOrderID = po.PurchaseOrderID) FROM PurchaseOrder as po where PurchaseOrderID = '" + Request.QueryString["PurchaseOrderID"] + "' ";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
lblstat.Text = "แก้ไขสถานะ รอการจัดส่ง เรียบร้อย";
}
}
</script>
<html>
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Cartoon2ndHand</title>
<style type="text/css">
body {
background-image: url(images/bg.gif);
background-repeat: repeat;
}
a {
font-size: 10px;
}
.style9
{
height: 31px;
}
.style10
{
height: 26px;
}
.style16 {font-size: 18px}
.style26 {font-family: "Microsoft Sans Serif"; font-size: 18px; }
.style30 {font-size: 24px}
-->
</style></head>
<body><form id="form1" runat="server">
<table width="961" height="1281" border="0" align="center">
<tr>
<td width="1024" height="1277" valign="top"><table width="955" height="1275" border="0">
<tr>
<td width="949" height="132"><div align="center"><img src="images/header edit.jpg" width="934" height="126" /></div></td>
</tr>
<tr>
<td class="style10"><table height="35" border="0" align="center"
style="width: 949px">
<tr align="center">
<td width="173" class="style9"><a href="default.aspx"><img src="images/Tab home.jpg" width="150" height="30" border="0" /></a></td>
<td width="150" class="style9"><a href="page1.aspx"><img src="images/Tab product light.jpg" width="150" height="30" border="0"></a></td>
<td width="150" class="style9"><a href="page2.aspx"><img src="images/Tab Buy the book..jpg" width="150" height="30" border="0"></a></td>
<td width="150" class="style9"><a href="page3.aspx"><img src="images/Tab How to order.jpg" width="150" height="30" border="0"></a></td>
<td width="150" class="style9"><a href="page4.aspx"><img src="images/Tab Contact us.jpg" width="150" height="30" border="0"></a></td>
<td width="222" class="style9"><asp:HyperLink id="hplLogout" NavigateURL="Logout.aspx" runat="server"><img src="images/logout.jpg" width="150" height="30"></asp:HyperLink></td>
</tr>
</table></td>
</tr>
<tr>
<td height="1097" valign="top"><table width="949" height="1095" border="0">
<tr>
<td width="180" height="1091" valign="top"><table width="180" height="500" border="1" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="204">
<asp:Label ID="lblStatus" runat="server" Text="Label"></asp:Label>
<div align="center"></div></td>
</tr>
<tr>
<td><div align="center" class="style26"><a href="page5-1.aspx" class="style16">ดูรายการสินค้าออก</a></div></td>
</tr>
<tr>
<td><div align="center" class="style26"><a href="page5-2.aspx" class="style16">ดูรายการสินค้าเข้า</a></div></td>
</tr>
<tr>
<td><div align="center" class="style26"><a href="page5-3.aspx" class="style16">แก้ไขข้อมูลสินค้า</a></div></td>
</tr>
<tr>
<td><div align="center" class="style26"><a href="page5-4.aspx" class="style16">จัดการรูปสินค้า</a></div></td>
</tr>
<tr>
<td><div align="center" class="style26"><a href="page5-5.aspx" class="style16">เพิ่มสินค้าเข้า</a></div></td>
</tr>
<tr>
<td><div align="center" class="style26"><a href="page5-5.aspx" class="style16">ออกรายงาน</a></div></td>
</tr>
</table></td>
<td width="759" valign="top"><p style="text-align: left"><img src="images/managepurchase.jpg" width="700" height="35"><br />
<br />
<asp:HiddenField id="HiddenField1" runat="Server"></asp:HiddenField>
<asp:HiddenField id="HiddenField2" runat="Server"></asp:HiddenField>
<asp:GridView id="myGridView"
runat="server" AutoGenerateColumns="False"
ShowFooter="True"
DataKeyNames="PurchaseOrderDetailID"
OnRowEditing="modEditCommand"
OnRowCancelingEdit="modCancelCommand"
OnRowDeleting="modDeleteCommand"
OnRowUpdating="modUpdateCommand"
onRowDataBound="myGridView_RowDataBound"
OnRowCommand="myGridView_RowCommand" Height="59px" Width="530px" CaptionAlign="Right">
<RowStyle Font-Size="Medium" HorizontalAlign="Right" />
<Columns>
<asp:TemplateField HeaderText="รหัสใบสั่งซื้อ">
<ItemTemplate>
<asp:Label id="lblPurchaseOrderID" runat="server" ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditPurchaseOrderID" size="12" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PurchaseOrderID") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddPurchaseOrderID" size="12" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="รหัสรายละเอียดการสั่งซื้อ">
<ItemTemplate>
<asp:Label id="lblPurchaseOrderDetailID" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditPurchaseOrderDetailID" size="12" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PurchaseOrderDetailID") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddPurchaseOrderDetailID" size="12" runat="server" ReadOnly="true" BackColor="GrayText"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="รหัสสินค้า">
<ItemTemplate>
<asp:Label id="lblProductID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="txtEditProductID" runat="server"> </asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtAddProductID" runat="server" > </asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ชื่อสินค้า">
<ItemTemplate>
<asp:Label id="lblProductName" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditProductName" size="30" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddProductName" size="30" runat="server" ReadOnly="true" BackColor="GrayText"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="จำนวนสินค้าที่สั่ง">
<ItemTemplate>
<asp:Label id="lblOrderQuantity" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditOrderQuantity" size="10" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OrderQuantity") %>'></asp:TextBox><br />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddOrderQuantity" size="10" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="จำนวนสินค้าที่ได้รับ">
<ItemTemplate>
<asp:Label id="lblReceiveQuantity" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditReceiveQuantity" size="10" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ReceiveQuantity") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddPurchaseOrderDetailID1" size="12" runat="server" ReadOnly="true" BackColor="GrayText"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="สินค้าตกค้างส่งไม่ครบ" >
<ItemTemplate>
<asp:Label id="lblDiffQuantity" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="txtEditDiffQuantity" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DiffQuantity") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Label id="txtAddDiffQuantity" runat="server"></asp:Label>
<asp:Button id="btnAdd" runat="server" Text="เพิ่มรายการสั่งซื้อใหม่" size="40" CommandName="Add" ></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ราคา">
<ItemTemplate>
<asp:Label id="lblProductPrice" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditProductPrice" size="10" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductPrice") %>'></asp:TextBox><br />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddProductPrice" size="10" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="สถานะสินค้า" >
<ItemTemplate>
<asp:Label id="lblPStockChk" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PStockChk") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist id="txtEditPStockChk" style="margin-left: 1px" Width="105px" runat="server" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>ส่งของครบถ้วน</asp:ListItem>
<asp:ListItem>ส่งสินค้าไม่ครบ</asp:ListItem>
</asp:dropdownlist>
</EditItemTemplate>
<FooterTemplate>
<asp:dropdownlist id="txtAddPStockChk" style="margin-left: 1px" Width="105px" runat="server" >
<asp:ListItem>รอการส่งสินค้า</asp:ListItem>
</asp:dropdownlist>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ControlStyle-Font-Size="Large" ShowEditButton="True" CancelText="Cancel" DeleteText="Delete" EditText="Edit" UpdateText="Update" HeaderText="Modify" />
<asp:CommandField ControlStyle-Font-Size="Large" ShowDeleteButton="True" HeaderText="Delete" />
</Columns>
<FooterStyle BackColor="#6699FF" HorizontalAlign="Right" />
<PagerStyle Font-Size="Small" />
<HeaderStyle BackColor="#3399FF" />
<AlternatingRowStyle BackColor="#99CCFF" Font-Size="Medium"
HorizontalAlign="Right" />
</asp:GridView>
<br />
<asp:Label ID="Label1" runat="server" Text=" " Visible="false"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="จำนวนที่สั่งไปคือ " BackColor="Red"></asp:Label><br />
<br />
<table width="733" height="80" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="534" align="right" bgcolor="#FF9933"><div align="right">จำนวน (รายการ)</div></td>
<td width="193" align="right" bgcolor="#FF9933"><div align="right"><span class="style30"><asp:Label id="lblmyCount" runat="server"></asp:Label></span></div></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFF99"><div align="right">ราคารวม(บาท)</div></td>
<td align="right" bgcolor="#FFFF99"><div align="right"><span class="style30"><asp:Label id="lblmySum" runat="server"></asp:Label></span></div></td>
</tr>
</table>
<br />
<asp:RadioButton id="RadioButton1" runat="server" text="รับสินค้าแล้ว"
GroupName="Group1" ></asp:RadioButton>
<asp:RadioButton id="RadioButton2" runat="server" text="รอการจัดส่ง"
AutoPostBack="true" GroupName="Group1" Checked="true" ></asp:RadioButton>
<asp:Button ID="btnSave" runat="server" Height="26px" onclick="btnSave_Click"
style="height: 26px" Text="บันทึก" Width="49px" />
<br />
</p>
<p><br />
<asp:Label ID="lblstat" runat="server" ></asp:Label>
<br />
</p></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#
|
ประวัติการแก้ไข 2011-05-13 23:08:58
|
|
|
|
|
Date :
2011-05-13 23:00:56 |
By :
ekarit |
View :
1445 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณก็ทำตอน RowDataBound น่ะครับ โดยถ้าไม่ต้องการให้ Show ก็ใช้ Visible = false; ครับ
|
|
|
|
|
Date :
2011-05-14 08:03:58 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอ่อ มันใช้ this. เหมือนพวกปุ่มกดไม่ได้น่ะครับ ต้องใช้คำสั่งอะไรหรอครับ
|
|
|
|
|
Date :
2011-05-14 12:52:25 |
By :
ekarit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
Button btnSave = (Label)(e.Row.FindControl("btnSave"));
if (btnSave != null)
{
btnSave.Visible = false;
}
แทรกใน RowDataBound ครับ
|
|
|
|
|
Date :
2011-05-14 13:24:48 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|