 |
|
Gridview Asp.net ต้องการเอาเฉาพะรหัสที่เลือกแบบไม่ loop ทั้งหมด ยังไงครับ |
|
 |
|
|
 |
 |
|
ใช้ ItemCommand() 
|
 |
 |
 |
 |
Date :
2016-09-19 10:44:42 |
By :
Mr.T-Bag |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กำหนด Properties ของ LinkButton ในส่วนของ CommandName = "Select"
ที่ Function Gridview1_Selectedindex
สมมติว่า textbox ที่ต้องการเก็บค่ารหัสที่ต้องการชื่อ txtid.text
txtid.text = CType(GridView1.SelectedRow.Cells(1).FindControl("lblcode"), Label).Text.ToString
ผิดถูกยังไง ขออภัยครับ
|
 |
 |
 |
 |
Date :
2016-09-19 15:50:33 |
By :
Balll2iFFer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้เลยครับ
ตอบความคิดเห็นที่ : 4 เขียนโดย : Balll2iFFer เมื่อวันที่ 2016-09-19 15:50:33
รายละเอียดของการตอบ ::
Code (VB.NET)
Imports System.Data.SqlClient
Public Class Popup3
Inherits System.Web.UI.Page
Dim sql As String = ""
Dim Code As Label
Dim ss As String = ""
Private Sub SelectData()
Sql = "select ROW_NUMBER() OVER(ORDER BY Code) as Row, Code, Name1 From BCAP"
sql &= " where Code LIKE'%" & TextBox1.Text.Trim & "%'OR Name1 LIKE'%" & TextBox1.Text.Trim & "%'"
Dim DT As New DataTable
DT = New ClassConnectDBBC().SelectDB(Sql)
If DT.Rows.Count > 0 Then
GridView1.DataSource = DT
GridView1.DataBind()
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("UseStarting") = Nothing Then
Response.Redirect("~/UserAccount/LoginDB.aspx", True)
Else
Me.SelectData()
End If
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LinkButton1.Click
Me.SelectData()
End Sub
Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim lblCode As Label = CType(e.Row.FindControl("Label1"), Label)
If Not IsNothing(lblCode) Then
lblCode.Text = e.Row.DataItem("Code")
End If
End Sub
Private Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Code.Text = CType(GridView1.SelectedRow.Cells(2).FindControl("Label1"), Label).Text.ToString
ss = Code.Text
End Sub
Protected Sub LinkButton2_Click1(ByVal sender As Object, ByVal e As EventArgs)
MsgBox(ss)
End Sub
End Class
Code (ASP)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="PopupAp.aspx.vb" Inherits="WebApplication1.Popup3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function OpenPopup(url) {
popup = window.open(url, "mypopup", "location=1,status=1,scrollbars=1,width=400,height=250");
popup.moveTo(0, 0);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="401px"></asp:TextBox>
<asp:LinkButton ID="LinkButton1" runat="server">ค้นหา</asp:LinkButton>
<table align="center" style="width: 100%;">
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Width="914px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="เลือก">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click1">เลือก</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ลำดับ">
<ItemTemplate>
<asp:Label ID="Lbl" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Row") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="รหัส">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Code") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ชื่อลูกค้า">
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Name1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
|
ประวัติการแก้ไข 2016-09-19 16:26:44
 |
 |
 |
 |
Date :
2016-09-19 16:20:15 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ได้ละครับแต่ไม่รู้เป็นวิธีที่ใช้อยู่ไหมครับ
Code (ASP)
DataKeyNames="Code"
OnSelectedIndexChanging = "modSelectCommand"
Code (VB.NET)
Sub modSelectCommand(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Session("Re_Code") = GridView1.DataKeys.Item(e.NewSelectedIndex).Value
End Sub
|
ประวัติการแก้ไข 2016-09-22 16:26:15 2016-09-22 16:26:54
 |
 |
 |
 |
Date :
2016-09-22 16:17:29 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|