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,038

HOME > .NET Framework > Forum > อยากทราบใครมี cod บันทึก textbox ลง datagridview ได้บ้างคะ


 

[.NET] อยากทราบใครมี cod บันทึก textbox ลง datagridview ได้บ้างคะ

 
Topic : 058133



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



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



อยากทราบเมื่อเราบันทึกข้อมูลลง textbox แล้วทำไมไม่บันทึกลงฐานข้อมูล โดยให้โชว์ที่ datagridview แล้วสามารถ link เปิดไฟล์เอกสารได้ (นามสกุล .pdf , .jpg, .gif)



Tag : ASP.NET, Web (ASP.NET)

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-04-01 09:41:57 By : cazyboy View : 1637 Reply : 2
 

 

No. 1



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

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

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

ใช้ RowCommand ของ GridView ครับ

Code (VB.NET)
01.Sub myGridView_RowCommand(source As Object, e As GridViewCommandEventArgs)
02.    If e.CommandName = "Add" Then
03.        '*** CustomerID ***'
04.        Dim txtCustomerID As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCustomerID"), TextBox)
05.        '*** Email ***'
06.        Dim txtName As TextBox = CType(myGridView.FooterRow.FindControl("txtAddName"), TextBox)
07.        '*** Name ***'
08.        Dim txtEmail As TextBox = CType(myGridView.FooterRow.FindControl("txtAddEmail"), TextBox)
09.        '*** CountryCode ***'
10.        Dim txtCountryCode As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCountryCode"), TextBox)
11.        '*** Budget ***'
12.        Dim txtBudget As TextBox = CType(myGridView.FooterRow.FindControl("txtAddBudget"), TextBox)
13.        '*** Used ***'
14.        Dim txtUsed As TextBox = CType(myGridView.FooterRow.FindControl("txtAddUsed"), TextBox)
15. 
16.        strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
17.        " VALUES ('" & txtCustomerID.Text & "','" & txtName.Text & "','" & txtEmail.Text & "' " & _
18.        " ,'" & txtCountryCode.Text & "','" & txtBudget.Text & "','" & txtUsed.Text & "') "
19.        objCmd = New OleDbCommand(strSQL, objConn)
20.        objCmd.ExecuteNonQuery()
21. 
22.        BindData()
23.    End If
24.End Sub


ส่วน Link ทำกใน RowDataBound ครับ

Code (VB.NET)
1.'*** CustomerID ***'
2.Dim hplCustomerID As Hyperlink = CType(e.Row.FindControl("hplCustomerID"),Hyperlink)
3.IF Not IsNothing(hplCustomerID) Then
4.    hplCustomerID.Text = e.Row.DataItem("CustomerID")
5.    hplCustomerID.NavigateUrl  = "Page.aspx?CustomerID=" & e.Row.DataItem("CustomerID")
6.End IF


Code เต็ม ๆ

Code (VB.NET)
001.<%@ Page Language="VB" %>
002.<%@ import Namespace="System.Data" %>
003.<%@ import Namespace="System.Data.OleDb" %>
004.<script runat="server">
005. 
006.    Dim objConn As OleDbConnection
007.     Dim objCmd As OleDbCommand
008. 
009.     Sub Page_Load(sender As Object, e As EventArgs)
010.            Dim strConnString As String
011.            strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
012.            Server.MapPath("database/mydatabase.mdb")&";"
013.            objConn = New OleDbConnection(strConnString)
014.            objConn.Open()
015. 
016.            IF Not Page.IsPostBack() Then
017.                BindData()
018.            End IF
019.     End Sub
020. 
021.    Sub BindData()
022.           Dim strSQL As String
023.           strSQL = "SELECT * FROM customer"
024. 
025.           Dim dtReader As OleDbDataReader
026.           objCmd = New OleDbCommand(strSQL, objConn)
027.           dtReader = objCmd.ExecuteReader()
028. 
029.           '*** BindData to GridView ***'
030.           myGridView.DataSource = dtReader
031.           myGridView.DataBind()
032. 
033.           dtReader.Close()
034.           dtReader = Nothing
035. 
036.    End Sub
037. 
038.    Sub Page_UnLoad()
039.           objConn.Close()
040.           objConn = Nothing
041.    End Sub
042. 
043.    Private Sub myGridView_RowDataBound(sender As Object, e As GridViewRowEventArgs)
044.        '*** CustomerID ***'
045.        Dim hplCustomerID As Hyperlink = CType(e.Row.FindControl("hplCustomerID"),Hyperlink)
046.        IF Not IsNothing(hplCustomerID) Then
047.            hplCustomerID.Text = e.Row.DataItem("CustomerID")
048.            hplCustomerID.NavigateUrl  = "Page.aspx?CustomerID=" & e.Row.DataItem("CustomerID")
049.        End IF
050. 
051.        '*** Email ***'
052.        Dim lblName As Label = CType(e.Row.FindControl("lblName"),Label)
053.        IF Not IsNothing(lblName) Then
054.            lblName.Text = e.Row.DataItem("Name")
055.        End IF
056. 
057.        '*** Name ***'
058.        Dim lblEmail As Label = CType(e.Row.FindControl("lblEmail"),Label)
059.        IF Not IsNothing(lblEmail) Then
060.            lblEmail.Text = e.Row.DataItem("Email")
061.        End IF
062. 
063.        '*** CountryCode ***'
064.        Dim lblCountryCode As Label = CType(e.Row.FindControl("lblCountryCode"),Label)
065.        IF Not IsNothing(lblCountryCode) Then
066.            lblCountryCode.Text = e.Row.DataItem("CountryCode")
067.        End IF
068. 
069.        '*** Budget ***'
070.        Dim lblBudget As Label = CType(e.Row.FindControl("lblBudget"),Label)
071.        IF Not IsNothing(lblBudget) Then
072.            lblBudget.Text = FormatNumber(e.Row.DataItem("Budget"),2)
073.        End IF
074. 
075.        '*** Used ***'
076.        Dim lblUsed As Label = CType(e.Row.FindControl("lblUsed"),Label)
077.        IF Not IsNothing(lblUsed) Then
078.            lblUsed.Text = FormatNumber(e.Row.DataItem("Used"),2)
079.        End IF
080.    End Sub
081. 
082.</script>
083.<html>
084.<head>
085.    <title>ThaiCreate.Com ASP.NET - GridView</title>
086.</head>
087.<body>
088.<form id="form1" runat="server">
089.<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False" onRowDataBound="myGridView_RowDataBound">
090. 
091.    <Columns>
092. 
093.    <asp:TemplateField HeaderText="Select">
094.        <ItemTemplate>
095.            <asp:HyperLink id="hplCustomerID" runat="server"></asp:HyperLink>
096.        </ItemTemplate>
097.    </asp:TemplateField>
098. 
099.    <asp:TemplateField HeaderText="CustomerID">
100.        <ItemTemplate>
101.            <asp:Label id="lblCustomerID" runat="server"></asp:Label>
102.        </ItemTemplate>
103.    </asp:TemplateField>
104. 
105.    <asp:TemplateField HeaderText="Name">
106.        <ItemTemplate>
107.            <asp:Label id="lblName" runat="server"></asp:Label>
108.        </ItemTemplate>
109.    </asp:TemplateField>
110. 
111.    <asp:TemplateField HeaderText="Email">
112.        <ItemTemplate>
113.            <asp:Label id="lblEmail" runat="server"></asp:Label>
114.        </ItemTemplate>
115.    </asp:TemplateField>
116. 
117.    <asp:TemplateField HeaderText="CountryCode">
118.        <ItemTemplate>
119.            <asp:Label id="lblCountryCode" runat="server"></asp:Label>
120.        </ItemTemplate>
121.    </asp:TemplateField>
122. 
123.    <asp:TemplateField HeaderText="Budget">
124.        <ItemTemplate>
125.            <asp:Label id="lblBudget" runat="server"></asp:Label>
126.        </ItemTemplate>
127.    </asp:TemplateField>
128. 
129.    <asp:TemplateField HeaderText="Used">
130.        <ItemTemplate>
131.            <asp:Label id="lblUsed" runat="server"></asp:Label>
132.        </ItemTemplate>
133.    </asp:TemplateField>
134. 
135.    </Columns>
136. 
137.</asp:GridView>
138.</form>
139.</body>
140.</html>



Go to : (ASP.NET)จะใช้ HyperLink ใน GridView นี้ใช้ยังไงอ่ะครับ.ในหน้าเลือกซื้อสินค้าจะมีชื่อสินค้าอยู่ โดยที่เราสามารถกดเพื่อดูรายละเอียดของสินค้านั้นได้..

Go to : ขอความเห็นในเรื่องการทำ HyperLink ใน Gridview เพื่อแสดงไปอีกหน้าหนึ่งในลักษณะ Masterpage

Go to : ทำ Hyperlink เพื่อทำการ Download File ใน Gridview อย่างไรหรอครับ

Go to : เรื่อง Gridview ในการดึงข้อมูลจากตาราง A มาโชว์ แล้วกดที่ HyperLink แล้วจะให้ไปเพิ่มในตาราง B ทำยังไงครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-01 10:04:47 By : webmaster
 

 

No. 2



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



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


ขอบคุณคร๊าบ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-04 12:46:06 By : cazyboy
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทราบใครมี cod บันทึก textbox ลง datagridview ได้บ้างคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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