Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ขอคำแนะนำ เรื่องการ add row โดยรับค่ามาจากอีก เพจนึง เข้าGridview



 

ขอคำแนะนำ เรื่องการ add row โดยรับค่ามาจากอีก เพจนึง เข้าGridview

 



Topic : 058010



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์




sss


ขอคำแนะนำหน่อยครับ ว่าตามรูปทำอย่างไร โดยจะเพิ่ม แถว โดยแต่ละแถวแสดงดังรูปอะครับ ช่องแรก เพิ่มรูปภาพ ช่องสอง เพิ่ม รายละเอียดอะครับ มีราคา กับชื่อสินค้า

โดยรับ ProductID มาจากอีก Page นึง ช่วยชี้แนะด้วยครับ แต่น่าจะใช้datatable ใช่ไหมครับ มีโค๊ดตัวอย่างจะขอบคุณมากมาย



Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET, C#, VS 2005 (.NET 2.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-03-29 17:00:52 By : kasapa111 View : 1554 Reply : 9
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ทำได้หลายวิธีครับ ใช้ Session กับ DataTable ก็ได้ครับ ส่วน GridView ก็เพียงโยนค่า Session ของ DataTable ก็ได้แล้วครับ

Code (ASP.NET)
Dim dt As DataTable
dt = Session("mySession")

Dim dr As DataRow
dr = dt.NewRow
dr("CustomerID") = "C001"
dr("Name") = "Win Weerachai"
dr("Email") = "[email protected]"
dr("CountryCode") = "TH"
dr("Budget") = "1000000"
dr("Used") = "600000"
dt.Rows.Add(dr)

Session("mySession") = dt



ขอวิธีการเอาข้อมูลจาก gridview ลงไปอีกตารางหนึ่งหน่อยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-29 20:52:26 By : webmaster
 


 

No. 2



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


จะทำยังไงให้ ปุ่มตรงฟุตเตอร์ ทำงานในGridview ได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-01 19:36:05 By : kasapa111
 

 

No. 3



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


ลองใช้ findcontrol แล้ว แต่มันไม่ทำงานอะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-01 20:19:42 By : kasapa111
 


 

No. 4

Guest


Code (C#)
    private void RowDataBound(object Sender, GridViewRowEventArgs e)
    {     

        switch (e.Row.RowType)
        {
            case DataControlRowType.Footer :
                //find control here 
                break;
        }
    }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-01 23:12:00 By : สาวเอ๋อ เอ๋อเหรอ เอ๋อมากมาย
 


 

No. 5



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


จาก โพสคุณพี่วิน ผมขอถามหน่อยนะครับว่า อยากเพิ่มคอลลัมเพิ่ม จากที่มีอยู่ ต้องทำยังไงครับ คือ คอลัมส่วนแรกเอามาจากดาต้าเบต
คือพวกรายละเอียดสินค้า ดึงมาจากดาต้าเบต ทีนี้จะเพิ่มคอลลัม จำนวน กับ ผลรวมครับ ซึ้งต้องการเพิ่มขึ้นมาใหม่ แล้ว เพิ่มลงในdatatable

อันนี้คือโค๊ดที่ลองทำนะครับ ติดปัญหาตรง ช่อง จำนวนอะครับ จะทำแบบ บนรูปข้างบนอะครับ
Code (ASP)
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Cart.aspx.cs" Inherits="Cart" Title="Untitled Page"  %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
    <br />
  
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" ShowFooter="True" Width="596px" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"   >
    <Columns>
    				<asp:TemplateField HeaderText="รูปสินค้า">
		<ItemTemplate>
	<asp:Image Width="100px" runat="server" ID="Pic" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.ProductPic_") %>'>
                    </asp:Image>
		</ItemTemplate>
		<ItemStyle Width="120px" />
                        <FooterTemplate>
                            &nbsp;<footertemplate></footertemplate>
                        </FooterTemplate>
		</asp:TemplateField>
		<asp:TemplateField HeaderText="รายการสินค้า">
		<ItemTemplate >
		           <table border="0" cellpadding="0" cellspacing="0" width="300">
                <tr align="center">
                    <td align="left" rowspan="2" style="width: 350px" valign="top">
                                        <asp:Label ID="lblProductName" runat="server"></asp:Label><br />
                                        <b>รหัสสินค้า</b> :  <asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductID") %>'></asp:Label><br />
                        <asp:Label ID="lblPrice" runat="server" Font-Bold="true"></asp:Label><br />
                        <b style="color: red;">
                            <asp:Label ID="lblSalePrice" runat="server"></asp:Label></b> <br />
                       <b>รายละเอียด:</b><br /> <asp:Label ID="lblDetail" runat="server" ></asp:Label>
   </td>
                </tr>
            </table>
		</ItemTemplate>
		<ItemStyle Width="300px" />
            <FooterTemplate>
                <asp:Button ID="btncal" runat="server" Height="27px" Text="คำนวนใหม่" Width="172px" OnClick="btncal_Click" />
            </FooterTemplate>
		</asp:TemplateField>
		    				<asp:TemplateField HeaderText="จำนวน">
		<ItemTemplate>
            &nbsp;<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Enabled="false"  >
            <asp:ListItem Text="1" Value="1"></asp:ListItem>
            <asp:ListItem Text="2" Value="2"></asp:ListItem>
            <asp:ListItem Text="3" Value="3"></asp:ListItem>
            <asp:ListItem Text="4" Value="4"></asp:ListItem>
            <asp:ListItem Text="5" Value="5"></asp:ListItem>
            <asp:ListItem Text="6" Value="6"></asp:ListItem>
            <asp:ListItem Text="7" Value="7"></asp:ListItem>
            <asp:ListItem Text="8" Value="8"></asp:ListItem>
            <asp:ListItem Text="9" Value="9"></asp:ListItem>
            <asp:ListItem Text="10" Value="10"></asp:ListItem>
            </asp:DropDownList>
		</ItemTemplate>
		<ItemStyle Width="60px" />
                                <FooterTemplate>
                                    <strong><span style="font-size: 10pt">รวม</span></strong>
                                </FooterTemplate>
		</asp:TemplateField>
				    				<asp:TemplateField HeaderText="ราคา">
		<ItemTemplate>
           <center><asp:Label ID="lblPricetotal" runat="server" Font-Bold="true"></asp:Label></center>  
		</ItemTemplate>
		<ItemStyle Width="100px" />
                                        <FooterTemplate>
                                            
                                            <asp:Label ID="total" runat="server" Text="0" ></asp:Label>.00 บาท
                                            
                                        </FooterTemplate>
		</asp:TemplateField>
		<asp:CommandField ShowEditButton="True" />
		<asp:CommandField ShowDeleteButton=True CancelText="ลบ" >
            <ItemStyle Width="10px" />
        </asp:CommandField>
		
    </Columns>
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
    </asp:GridView>

    <asp:Button ID="btnselect" runat="server" Height="33px" OnClick="btnselect_Click"
        Text="เลือกสินค้าต่อ" />
    <asp:Button ID="btnpay" runat="server" Height="33px" OnClick="btnpay_Click" Text="ชำระเงิน"
        Width="89px" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>




Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Cart : System.Web.UI.Page
{
DataTable dt;
    String Ta;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGrid();
        }

    }
    protected void btnselect_Click(object sender, EventArgs e)
    {
        Response.Redirect("Products.aspx");
    }
    protected void btncal_Click(object sender, EventArgs e)
    {


    }
    protected void btnpay_Click(object sender, EventArgs e)
    {
        BindGrid();

    }
    void BindGrid()
    {
        try
        {
            String ID = Request.QueryString["ID"];
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["lajolieConn"].ToString()))
            {
                string sql;
                sql = "SELECT ProductName,ProductPrice,ProductPriceSpecial,ProductPic_,ProductDetail,ProductID ";
                sql += ",'" + "<b>ราคาพิเศษ  " + "'+ProductPriceSpecial+'" + ".00 บาท</b>" + "' AS PPS,'" + "ราคาปกติ " + "'+ProductPrice+'" + ".00 บาท" + "' AS PP,'" + "ราคา " + "'+ProductPrice+'" + ".00 บาท" + "' AS P ";
                sql += " FROM Product WHERE ProductID='" + ID + "' ";


                SqlCommand dacus = new SqlCommand(sql, conn);
                conn.Open();
                SqlDataReader dar = dacus.ExecuteReader();
                dar.Read();
                String ProductName = dar[0].ToString();
                String Price = dar[1].ToString();
                String PriceS = dar[2].ToString();
                String Pic = dar[3].ToString();
                String ProductDetail = dar[4].ToString();
                String ProductID = dar[5].ToString();
                String PriceSSP = dar[6].ToString();
                String PriceN = dar[7].ToString();
                String PriceP = dar[8].ToString();
                conn.Close();
                if (Session["mySession"] != null)
                {
                    
                    dt = Session["mySession"] as DataTable;


                    DataRow dr;
                    dr = dt.NewRow();
                    dr["ProductName"] = ProductName;
                    dr["ProductPrice"] =Price ;
                    dr["ProductPriceSpecial"] = PriceS;                
                    dr["ProductPic_"] = Pic;
                    dr["ProductDetail"] = ProductDetail;
                    dr["P"] = PriceP;
                    dr["PP"] = PriceN;
                    dr["PPS"] = PriceSSP;
                    dr["ProductID"] = ProductID;
                    dt.Rows.Add(dr);

                    Session["mySession"] = dt;

                }
                else
                {
                    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                    DataSet ds = new DataSet();
                    da.Fill(ds, ("tabel"));
                    dt= ds.Tables["tabel"];
                    Session["mySession"]=dt ;
                }
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }
        catch
        {
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
             {
            //*** lblCateID ***//
            Label lblName = (Label)(e.Row.FindControl("lblProductName"));
            Label lblNameDetail = (Label)(e.Row.FindControl("lblDetail"));
            Label lblUsed = (Label)(e.Row.FindControl("lblPrice"));
            Label lblUsed2 = (Label)(e.Row.FindControl("lblSalePrice"));
            Label lblUsed3 = (Label)(e.Row.FindControl("lblPricetotal"));
            Label lbltotal = (Label)(e.Row.FindControl("total"));
            Button btncal = (Button)(e.Row.FindControl("btncal"));
            DropDownList DropDownList1 = (DropDownList)(e.Row.FindControl("DropDownList1"));

            

            if (lblUsed2 != null)
            {
                if (Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ProductPriceSpecial")) == 0)
                {
                    lblName.Text = DataBinder.Eval(e.Row.DataItem, "ProductName").ToString();
                    lblName.ForeColor = System.Drawing.Color.Blue;
                    lblNameDetail.Text = DataBinder.Eval(e.Row.DataItem, "ProductDetail").ToString();
                    lblUsed.Text = DataBinder.Eval(e.Row.DataItem, "P").ToString();
                    lblUsed.ForeColor = System.Drawing.Color.Blue;
                    lblUsed2.Text = null;
                    String AA = DataBinder.Eval(e.Row.DataItem, "ProductPrice").ToString();
                    if (DropDownList1.SelectedValue == "1")
                    {
                        String A = DropDownList1.SelectedValue;
                        lblUsed3.Text = Convert.ToString(Convert.ToInt32(A) * Convert.ToInt32(AA));
                    }
                    else
                    {              
                        String A = DropDownList1.SelectedValue;
                        lblUsed3.Text = Convert.ToString(Convert.ToInt32(A) * Convert.ToInt32(AA));
                    }
                    
                }
                else
                {
                    lblName.Text = DataBinder.Eval(e.Row.DataItem, "ProductName").ToString();
                    lblName.ForeColor = System.Drawing.Color.Blue;
                    lblNameDetail.Text = DataBinder.Eval(e.Row.DataItem, "ProductDetail").ToString();
                    lblUsed.Text = DataBinder.Eval(e.Row.DataItem, "PP").ToString();
                    lblUsed.ForeColor = System.Drawing.Color.Gray;
                    lblUsed.Font.Strikeout = true;
                    lblUsed2.Text = DataBinder.Eval(e.Row.DataItem, "PPS").ToString();
                    String AA = DataBinder.Eval(e.Row.DataItem, "ProductPriceSpecial").ToString();
                    if (Session["Amount"] != null)
                    {
                        DropDownList1.SelectedValue = Convert.ToString( Session["Amount"]);
                    }
                    DropDownList1.SelectedValue= Convert.ToString( Session["Amount"]);
                    if (DropDownList1.SelectedValue == "1")
                    {
                        String A = DropDownList1.SelectedValue;
                        lblUsed3.Text = Convert.ToString(Convert.ToInt32(A) * Convert.ToInt32(AA));
                    }
                    else
                    {
                        String A = DropDownList1.SelectedValue;
                        lblUsed3.Text = Convert.ToString(Convert.ToInt32(A) * Convert.ToInt32(AA));
                    }

                }
                Session.Remove("Amount");

                Ta = Convert.ToString( Convert.ToInt32(lblUsed3.Text) + Convert.ToInt32(Ta));
                
            }


            if (e.Row.RowType == DataControlRowType.Footer)
            {
                lbltotal.Text = Ta.ToString();
            }
    }



ประวัติการแก้ไข
2011-04-04 23:26:39
2011-04-04 23:29:23
2011-04-04 23:40:11
2011-04-04 23:46:34
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-04 23:20:44 By : kasapa111
 


 

No. 6



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


คือ ออกแบบgridview มาแล้วดังcodeด้านบน คือโหลดครั้งแรกจะทำอย่างไร ให้datatable เพิ่มคอลัมม์ จำนวน และก็ราคา ได้อะครับ ซึ้งสองคอลัมม์นี้มันไม่มีในดาต้าเบต

089. {
090. SqlDataAdapter da = new SqlDataAdapter(sql, conn);
091. DataSet ds = new DataSet();
092. da.Fill(ds, ("tabel"));
093. dt= ds.Tables["tabel"];
094. Session["mySession"]=dt ;
095. }

ตรงส่วนนี้อะครับ จะเพิ่มยังไง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-05 19:14:20 By : kasapa111
 


 

No. 7



โพสกระทู้ ( 482 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ขอดูด้วย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-05 20:05:51 By : babyprogrammer
 


 

No. 8



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


จากcodeคือต้องการ ให้ dropdowlist รู้ ตำแหน่องของแต่ละแถวอะครับ เวลาbindอะครับ ช่วยหน่อย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-06 15:18:56 By : kasapa111
 


 

No. 9



โพสกระทู้ ( 13 )
บทความ ( 0 )



สถานะออฟไลน์


ช่วยแนะนำหน่อย อยากทราบว่ามันทำได้หรือเปล่า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-07 10:20:10 By : kasapa111
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอคำแนะนำ เรื่องการ add row โดยรับค่ามาจากอีก เพจนึง เข้าGridview
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่