<asp:GridView ID="grdSearch" runat="server" RowStyle-BackColor="White" AutoGenerateColumns="false" AllowPaging="false" HeaderStyle-BackColor="#FF33CC" HeaderStyle-ForeColor="#FFFFFF" HeaderStyle-Font-Bold="true" DataKeyNames="MealTypeID" onrowcreated="grdSearch_RowCreated" PageSize="20" Width="780px" onrowdatabound="grdSearch_RowDataBound" onrowcommand="grdSearch_RowCommand" onselectedindexchanged="grdSearch_SelectedIndexChanged" Height="194px" > <RowStyle BackColor="White" CssClass="text" /> <Columns> <asp:TemplateField HeaderText="No." ItemStyle-Width="50"> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="lblGridNo" runat="server" CssClass ="text"></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="MealType" DataField="MealTypeDes" ItemStyle-CssClass="text" ItemStyle-Width="250" HeaderStyle-Width="250" > <HeaderStyle Width="250px" /> <ItemStyle CssClass="text" Width="250px" /> </asp:BoundField> <asp:TemplateField HeaderText="" ItemStyle-Width="70" HeaderStyle-Width="70" > <HeaderTemplate> <asp:CheckBox ID="chkAdult" runat="server" Text="Adult" /> </HeaderTemplate> <ItemTemplate> <asp:TextBox ID="txtMealPrice1" runat="server" CssClass="text" ></asp:TextBox> </ItemTemplate> <HeaderStyle Width="70px" /> <ItemStyle Width="70px" /> </asp:TemplateField> <asp:TemplateField HeaderText="" ItemStyle-Width="70" HeaderStyle-Width="70" > <HeaderTemplate> <asp:CheckBox ID="chkChild" runat="server" Text="Child" /> </HeaderTemplate> <ItemTemplate> <asp:TextBox ID="txtMealPrice2" runat="server" CssClass="text" ></asp:TextBox> </ItemTemplate> <HeaderStyle Width="70px" /> <ItemStyle Width="70px" /> </asp:TemplateField> <asp:TemplateField HeaderText="" ItemStyle-Width="70" HeaderStyle-Width="70" > <HeaderTemplate> <asp:CheckBox ID="chkTeen" runat="server" Text="Teen" /> </HeaderTemplate> <ItemTemplate> <asp:TextBox ID="txtMealPrice3" runat="server" CssClass="text" ></asp:TextBox> </ItemTemplate> <HeaderStyle Width="70px" /> <ItemStyle Width="70px" /> </asp:TemplateField> <asp:TemplateField HeaderText="Currency"> <ItemTemplate> <asp:Label ID="lblCur" runat="server" Text="" CssClass="text" ForeColor="HotPink" Width="20" Font-Bold="true" ></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <HeaderStyle BackColor="#FF33CC" Font-Bold="True" CssClass="text" ForeColor="White" /> <EmptyDataTemplate><b>No MealType Data</b></EmptyDataTemplate> </asp:GridView>
private void Binddata() { eContractDBDataContext db = new eContractDBDataContext(); var chkMeal = from ml in db.Mealzs where ml.PropID == Request.QueryString["HotelID"].ToString().ToDecimal() where ml.ValidID == Request.QueryString["V"].ToString().ToDecimal() where ml.CurrencyID == Request.QueryString["cur"].ToString().ToDecimal() select ml; if (chkMeal.ToList().Count > 0) { for (int i = 0; i < grdSearch.Rows.Count; i++) { TextBox txtMealPrice1 = new TextBox(); txtMealPrice1 = grdSearch.Rows[i].FindControl("txtMealPrice1") as TextBox; txtMealPrice1.ReadOnly = false; TextBox txtMealPrice2 = new TextBox(); txtMealPrice2 = grdSearch.Rows[i].FindControl("txtMealPrice2") as TextBox; txtMealPrice2.ReadOnly = false; TextBox txtMealPrice3 = new TextBox(); txtMealPrice3 = grdSearch.Rows[i].FindControl("txtMealPrice3") as TextBox; txtMealPrice3.ReadOnly = false; foreach (var item in chkMeal) { if (grdSearch.DataKeys[i].Value.ToString().ToDecimal() == item.MealTypeID) { if (item.AgeID == 33) { txtMealPrice1.Text = item.MealPrice.ToString(); } if (item.AgeID == 34) { txtMealPrice2.Text = item.MealPrice.ToString(); } if (item.AgeID == 36) { txtMealPrice3.Text = item.MealPrice.ToString(); } if (Request.QueryString["mode"] != null) { CheckBox chkUse = new CheckBox(); chkUse = grdSearch.Rows[i].FindControl("chkUse") as CheckBox; chkUse.Checked = true; chkUse.Enabled = false; txtMealPrice1.ReadOnly = true; txtMealPrice2.ReadOnly = true; txtMealPrice3.ReadOnly = true; cmdSave.Visible = false; cmdUpdate.Visible = true; } } } } } }
protected void cmdUpdate_Click(object sender, EventArgs e) { eContractDBDataContext db = new eContractDBDataContext(); int icount = 0; for (int i = 0; i < grdSearch.Rows.Count; i++) { CheckBox chkUse = new CheckBox(); chkUse = grdSearch.Rows[i].FindControl("chkUse") as CheckBox; chkUse.Enabled = false; if (chkUse.Checked == true) { CheckBox chkAdult = new CheckBox(); chkAdult = grdSearch.Rows[i].FindControl("chkAdult") as CheckBox; CheckBox chkTeen = new CheckBox(); chkTeen = grdSearch.Rows[i].FindControl("chkTeen") as CheckBox; CheckBox chkChild = new CheckBox(); chkChild = grdSearch.Rows[i].FindControl("chkChild") as CheckBox; TextBox txtMealPrice1 = new TextBox(); txtMealPrice1 = grdSearch.Rows[i].FindControl("txtMealPrice1") as TextBox; if (txtMealPrice1.Text == "") { txtMealPrice1.Text = "0"; } TextBox txtMealPrice2 = new TextBox(); txtMealPrice2 = grdSearch.Rows[i].FindControl("txtMealPrice2") as TextBox; if (txtMealPrice2.Text == "") { txtMealPrice2.Text = "0"; } TextBox txtMealPrice3 = new TextBox(); txtMealPrice3 = grdSearch.Rows[i].FindControl("txtMealPrice3") as TextBox; if (txtMealPrice3.Text == "") { txtMealPrice3.Text = "0"; } if (Request.QueryString["mode"] != null) { if (txtMealPrice1.ReadOnly == false) { Mealz ml = new Mealz(); ml.Compulsory = "O"; ml.CreateBy = User.Identity.Name; ml.CurrencyID = Request.QueryString["cur"].ToString().ToDecimal(); ml.MealTypeID = grdSearch.DataKeys[i].Value.ToString().ToDecimal(); ml.PropID = Request.QueryString["HotelID"].ToString().ToDecimal(); ml.UpdateBy = ""; ml.UpdateTime = DateTime.Now; ml.ValidYear = ""; ml.ValidID = Request.QueryString["V"].ToString().ToDecimal(); if (chkAdult.Checked == true) { ml.AgeID = 33; ml.MealPrice = txtMealPrice1.Text.ToDecimal(); } if (chkTeen.Checked == true) { ml.AgeID = 34; ml.MealPrice = txtMealPrice2.Text.ToDecimal(); } if (chkChild.Checked == true) { ml.AgeID = 36; ml.MealPrice = txtMealPrice3.Text.ToDecimal(); } ml.UpdateBy = User.Identity.Name; ml.UpdateTime = DateTime.Now; db.Mealzs.InsertOnSubmit(ml); db.SubmitChanges(); chkUse.Enabled = false; } else { var editMeal = (from ml in db.Mealzs where ml.PropID == Request.QueryString["HotelID"].ToString().ToDecimal() where ml.ValidID == Request.QueryString["V"].ToString().ToDecimal() where ml.CurrencyID == Request.QueryString["cur"].ToString().ToDecimal() where ml.MealTypeID == grdSearch.DataKeys[i].Value.ToString().ToDecimal() select ml).First(); if(chkAdult.Checked == true) { editMeal.AgeID = 33 ; editMeal.MealPrice = txtMealPrice1.Text.ToDecimal(); } if(chkTeen.Checked == true) { editMeal.AgeID = 34 ; editMeal.MealPrice = txtMealPrice2.Text.ToDecimal(); } if(chkChild.Checked == true) { editMeal.AgeID = 36 ; editMeal.MealPrice = txtMealPrice3.Text.ToDecimal(); } editMeal.UpdateBy = User.Identity.Name; editMeal.UpdateTime = DateTime.Now; db.SubmitChanges(); } } else { var editMeal = (from ml in db.Mealzs where ml.PropID == Request.QueryString["HotelID"].ToString().ToDecimal() where ml.ValidID == Request.QueryString["V"].ToString().ToDecimal() where ml.CurrencyID == Request.QueryString["cur"].ToString().ToDecimal() where ml.MealTypeID == grdSearch.DataKeys[i].Value.ToString().ToDecimal() select ml).First(); if (chkAdult.Checked == true) { editMeal.AgeID = 33; editMeal.MealPrice = txtMealPrice1.Text.ToDecimal(); } if (chkTeen.Checked == true) { editMeal.AgeID = 34; editMeal.MealPrice = txtMealPrice2.Text.ToDecimal(); } if (chkChild.Checked == true) { editMeal.AgeID = 36; editMeal.MealPrice = txtMealPrice3.Text.ToDecimal(); } editMeal.UpdateBy = User.Identity.Name; editMeal.UpdateTime = DateTime.Now; db.SubmitChanges(); } icount = icount + 1; } } if (icount == 0) { Alert("er", "Please Choose Meal Type", true); return; } else { Alert(MsgType.FinishUpdate); return; } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง