 |
|
ASP.Net ช่วยด้วยยย ทำมานานแล้วยังไม่ได้เลยการใช้ RadioButton GridView |
|
 |
|
|
 |
 |
|
Check control ก่อนสิครับ แล้วก็ส่งค่อไปที่ตัวแปรแถวละ 1 ตัวหรือใช้ ARRAY ก็ได้น่ะครับ
จากนั้นค่อย ส่งค่าใส่ SQL statement เพื่ออัพเดตลง DB น่ะครับ
|
 |
 |
 |
 |
Date :
2013-05-18 22:26:35 |
By :
ธนวัฒน์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อย่าไปยึดติดกับ GridView ครับ (ผมมองเห็นแต่ ปัญหา แต่ผมมองไม่เห็นตัณหาของผมเอง) +55555
ลองใช้ Table ธรรมดานี่แหละแ้ก้ (ถอด) ปัญหา
ขอให้โชคดีครับ
[x] ...
|
 |
 |
 |
 |
Date :
2013-05-18 23:05:02 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สมมุติว่าผมกลับมาเป็นหนุ่มอีกครั้งหนึ่ง และผมอยากจะกระซิบข้างหูเบาเบาว่า
----- ขอลุงหอมแก้มได้หรือเปล่า? +55555
กระผม (ลุง) จะลองหัดเขียน Select x1, x2, x3 From GridView Where x ให้โดูครับ +55555
|
 |
 |
 |
 |
Date :
2013-05-18 23:16:20 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือคำถามเราดึงมาจากฐานข้อมูลนะค่ะ
ถ้าเราไม่ดึงมาใส่ในกริดวิว เราดึงมาใส่ใน table ได้หรอค่ะ ใช้วิธีไหน
|
 |
 |
 |
 |
Date :
2013-05-20 13:45:24 |
By :
กำลังเครียด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดึงมาใส่ table ได้อยู่แล้วครับ
ใช้ gridview มันก็ generate มาเป็น tag table
ใช้ repeater ก็ generate มาเป็น tag table เหมือนกัน
ถ้าใช้ gridview แนะนำให้ใช้ boundfield แทน templetefield
แล้วค่อย add radio button ใน event rowdatabound เอา
ส่วนใช้ repeater ก็ใช้ tablerow + radio button เป็น repeat item
หรือถ้างงหนักๆ ก็วนลูปเองเลยก็ได้ (ถ้าพอมีความรู้ html ด้วยนะ)
|
 |
 |
 |
 |
Date :
2013-05-20 14:39:03 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

อันนี้ลองทำแบบ table แต่หัวข้อคำถามในนี้ พิมใส่ใน lable เอง
แต่อยากต้องการให้ แต่ละ lable ดึงข้อมูลมาจากฐานข้อมูลข้างล่างค่ะ เราจะกำหนดให้ แต่ละแถวลงแต่ละ lable อย่างไร

การวนลูปไม่ค่อยมีพื้นฐาน html ค่ะ
|
 |
 |
 |
 |
Date :
2013-05-20 15:23:41 |
By :
กำลังเครียด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VBScript)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cmd As New SqlCommand
Dim dsChk As New DataSet
Dim daChk As New SqlDataAdapter
Dim sqlselect As String = ""
conn.Open()
sqlselect = "Select core from Core_Competency"
cmd = New SqlCommand()
dsChk.Clear()
daChk = New SqlDataAdapter(sqlselect, conn)
daChk.Fill(dsChk, "Core_Competency")
With cmd
.CommandType = CommandType.Text
.CommandText = sqlselect
.Connection = conn
dr = .ExecuteReader()
End With
dr.Read()
If dr.HasRows Then
Label1.Text = CStr(dr(0))
End If
dr.Close()
End Sub

จากโค้ดจะได้ข้อมูลมาบรรทัดแรกของในฐาน แต่ถ้าจะ กำหนดให้ Lable1.text = คำถามข้อ1 , Lable2.text = คำถามข้อ2 เรื่อยๆ
ไม่รู้ว่าจะกำหนดให้เลือก cell 0 แต่ row 1,2, อย่างไรค่ะ
|
 |
 |
 |
 |
Date :
2013-05-20 15:40:02 |
By :
กำลังเครียก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Poll.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Poll.aspx.cs" Inherits="Poll" %>
<!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>Poll</title>
<style type="text/css">
table { border-spacing: 0px; border-collapse:collapse; }
th { border: 1px solid; padding: 5px; background-color: lightyellow; }
td { border: 1px solid; padding: 5px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table>
<tr>
<th rowspan="2">Core Competency (สมรรถนะความสามารถหลัก)</th>
<th colspan="10">ระดับคะแนน</th>
</tr>
<tr>
<th>0.5</th>
<th>1.0</th>
<th>1.5</th>
<th>2.0</th>
<th>2.5</th>
<th>3.0</th>
<th>3.5</th>
<th>4.0</th>
<th>4.5</th>
<th>5.0</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="LabelSubject" runat="server" Text="Label"></asp:Label></td>
<td><asp:RadioButton ID="RadioButton05" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton10" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton15" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton20" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton25" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton30" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton35" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton40" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton45" runat="server" /></td>
<td><asp:RadioButton ID="RadioButton50" runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
Poll.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Poll : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
Button1.Click += new EventHandler(Button1_Click);
if (!Page.IsPostBack)
{
DataTable dt = GetData();
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
Label lableSubject = (Label)item.FindControl("LabelSubject");
PlaceHolder1.Controls.Add(new LiteralControl(lableSubject.Text));
(from c in item.Controls.Cast<Control>()
where c.GetType() == typeof(RadioButton)
select c).ToList().ForEach(c =>
{
RadioButton radioButton = (RadioButton)c;
if (radioButton.Checked)
PlaceHolder1.Controls.Add(new LiteralControl(string.Format(" = {0} คะแนน",(Convert.ToDouble(radioButton.ID.Substring(radioButton.ID.Length - 2, 2)) / 10).ToString("0.0"))));
});
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
}
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
Label lableSubject = (Label)e.Item.FindControl("LabelSubject");
lableSubject.Text = (string)drv["Subject"];
(from c in e.Item.Controls.Cast<Control>()
where c.GetType() == typeof(RadioButton)
select c).ToList().ForEach(c =>
{
RadioButton radioButton = (RadioButton)c;
radioButton.GroupName = (string)drv["Code"];
});
}
}
protected DataTable GetData()
{
// ถ้าใช้งานจริงให้เปลี่ยนจากสร้าง datatable เป็น query จาก database
string[][] data = new string[][]
{
new string[] { "C0001", "การร่วมแรงร่วมใจและการทำงานเป็นทีม (Coopercation & Teamwork)" },
new string[] { "C0002", "ความซื่อสัตย์และจรยาบรรณ (Integrity & Ethics)" },
new string[] { "C0003", "การให้ความสำคัญกับลูกค้า (Customer focus)" },
new string[] { "C0004", "การพัฒนาเพื่อความเป็นเลิศ (Dedication to Quality Excellence)" },
new string[] { "C0005", "ความยึดมั่นในผลสำเร็จของงาน (Result Orientation)" },
new string[] { "C0006", "การตระหนักถึงต้นทุนทางธุรกิจ (Cost Sensitivity)" },
new string[] { "C0007", "ความกระตือรือร้นในการเรียนรู้ (Motivation to Learn)" }
};
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Code", typeof(string)));
dt.Columns.Add(new DataColumn("Subject", typeof(string)));
(from d in data
select d).ToList().ForEach(d =>
{
DataRow dr = dt.NewRow();
dr["Code"] = d[0];
dr["Subject"] = d[1];
dt.Rows.Add(dr);
});
return dt;
}
}
รัน

กด submit

|
 |
 |
 |
 |
Date :
2013-05-21 14:12:25 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
T__T เค้าใช้ VB นะ ไม่ใช่ C#
ไม่เคยใช้ C# งงเลยนะ
แต่ขอบคุณมากนะค่ะที่มาช่วยตอบ
ถ้าไม่รบกวนมาก ขอเป็นโค้ด VB นะค่ะ และขอเป็น query จาก database ด้วยนะ
ขอโทษนะถ้ารบกวนมากไป เราทำไม่เป็นจริงๆ เพิ่งเรียบจบมาทำงาน ไม่มีคนสอนงานด้วย ทำคนเดียว เลยพึ่งแต่ internet
|
 |
 |
 |
 |
Date :
2013-05-22 08:18:56 |
By :
กำลังเครียด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้เป็นตัวอย่างเอาไปศึกษานะ
ครั้งหน้าไม่ให้โค้ดแล้วนะ
PollVb.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Partial Class PollVb
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
' ตรวจสอบว่าถ้าไม่ได้ postback ให้ทำการ bind ข้อมูล
If Not Page.IsPostBack Then
Dim dt As DataTable = GetData()
Repeater1.DataSource = dt
Repeater1.DataBind()
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
' วนลูป item ใน repeater itemcollection
For Each item As RepeaterItem In Repeater1.Items
' ตรวจสอบ itemtype ให้ทำเฉพาะที่เป็น item กับ alternating item
If item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem Then
' ค้นหา label ชื่อ "LabelSubject" ใน repeater itemtemplate และ add label ลงใน placeholder1
Dim lableSubject As Label = DirectCast(item.FindControl("LabelSubject"), Label)
PlaceHolder1.Controls.Add(New LiteralControl(lableSubject.Text))
' query radiobutton ใน repeater itemtemplate ด้วย linq
Dim rdb = From r In item.Controls.Cast(Of Control)()
Where r.GetType() = GetType(RadioButton)
Select r
' วนลูป radiobutton ที่ qeury มา
For Each r As RadioButton In rdb.ToList()
Dim radioButton As RadioButton = DirectCast(r, RadioButton)
' ตรวสอบว่า radiobutton มีการ checked
If (radioButton.Checked) Then
' แสดงผลคะแนนลงใน placeholder1
PlaceHolder1.Controls.Add(New LiteralControl(String.Format(" = {0} คะแนน", (Convert.ToDouble(radioButton.ID.Substring(radioButton.ID.Length - 2, 2)) / 10).ToString("0.0"))))
End If
Next
' แสดงผลขึ้นบรรทัดใหม่ใน placeholder1
PlaceHolder1.Controls.Add(New LiteralControl("<br />"))
End If
Next
End Sub
Protected Sub Repeater1_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
' ตรวจสอบ itemtype ให้ทำเฉพาะที่เป็น item กับ alternating item
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
' แปลง type ของ dataitem เป็น datarowview
Dim drv As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
' ค้นหา label ชื่อ "LabelSubject" ใน repeater itemtemplate
Dim labelSubject As Label = DirectCast(e.Item.FindControl("LabelSubject"), Label)
labelSubject.Text = DirectCast(drv("Subject"), String)
' query radiobutton ใน repeater itemtemplate ด้วย linq
Dim rdb = From r In e.Item.Controls.Cast(Of Control)()
Where r.GetType() = GetType(RadioButton)
Select r
' วนลูป radiobutton ที่ qeury มาและกำหนด groupname
For Each r As RadioButton In rdb.ToList()
Dim radioButton As RadioButton = DirectCast(r, RadioButton)
radioButton.GroupName = DirectCast(drv("Code"), String)
Next
End If
End Sub
Protected Function GetData() As DataTable
' ถ้าใช้งานจริงให้เปลี่ยนจากสร้าง datatable เป็น query จาก database
Dim data As String()() = New String()() { _
New String() {"C0001", "การร่วมแรงร่วมใจและการทำงานเป็นทีม (Coopercation & Teamwork)"}, _
New String() {"C0002", "ความซื่อสัตย์และจรยาบรรณ (Integrity & Ethics)"}, _
New String() {"C0003", "การให้ความสำคัญกับลูกค้า (Customer focus)"}, _
New String() {"C0004", "การพัฒนาเพื่อความเป็นเลิศ (Dedication to Quality Excellence)"}, _
New String() {"C0005", "ความยึดมั่นในผลสำเร็จของงาน (Result Orientation)"}, _
New String() {"C0006", "การตระหนักถึงต้นทุนทางธุรกิจ (Cost Sensitivity)"}, _
New String() {"C0007", "ความกระตือรือร้นในการเรียนรู้ (Motivation to Learn)"}}
Dim dt As New DataTable()
dt.Columns.Add(New DataColumn("Code", GetType(String)))
dt.Columns.Add(New DataColumn("Subject", GetType(String)))
For Each d As String() In data
Dim dr As DataRow = dt.NewRow()
dr("Code") = d(0)
dr("Subject") = d(1)
dt.Rows.Add(dr)
Next
Return dt
End Function
Protected Function GetDbData() As DataTable
' สร้าง connection
Dim connectionString As String = "...................."
Dim connection As New SqlConnection(connectionString)
' สร้าง command
Dim commandString As String = "SELECT [id_core] AS [Code], [core] AS [Subject] FROM [Core_Competency]"
Dim command As New SqlCommand(commandString, connection)
' query ข้อมูลมาใส่ datatable
Dim dt As New DataTable()
Dim dataAdapter As New SqlDataAdapter(command)
dataAdapter.Fill(dt)
Return dt
End Function
End Class
|
 |
 |
 |
 |
Date :
2013-05-22 10:45:12 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
***** (ห้าดาว)
วิธีหาตัวอย่างมันตอบโจทย์ ASP.NET (Web) ได้ครบถ้วนสมบูรณ์แบบ อทิเช่น
--- การวนลูปบน HTML Table (โดยใช้ Repeater แทน GridView) *****
--- การเลือกใช้ Controls เหมาะสมกับลักษณะของงาน *****
--- LINQ, Lamda ค่อนข้างจะลงตัว
--- String Array และเทคนิคการเขียนโปรแกรม *****
------- Dim data As String()() == Dim data As New List(Of String) From {...}
------- Dim data As String()()()()()() *****
--- การแปลงค่า (Convert) และ เทคนิคการหาค่าจากชื่อของตัวแปร (Valueable & Variable) *****
--- etc
ยอดเยี่ยมจริงฯ ครับ
#NO...
Sourcecode C# และ VB มันสมบูรณ์แบบและน่าสนใจมากฯ ครับ
#NO 11 บรรทัดที่ 78
Code (VB.NET)
Protected Function GetData() As DataTable
Dim dt As New DataTable()
dt.Columns.Add(New DataColumn("Code", GetType(String)))
dt.Columns.Add(New DataColumn("Subject", GetType(String)))
'ไม่ต้องแปลงเป็น Enumerable
data.ToList().ForEach(Sub(d)
Dim dr As DataRow = dt.NewRow()
dr.Item("Code") = d(0)
dr.Item("Subject") = d(1)
End Sub)
'//data.ToList().ForEach(d =>
'// {
'// DataRow dr = dt.NewRow();
'// dr["Code"] = d[0];
'// dr["Subject"] = d[1];
'// dt.Rows.Add(dr);
'// });
Return dt
End Sub
#NO11 บรรทัดที่ 53
Code (VB.NET)
Protected Sub Repeater1_ItemDataBound(sender As Object,...
For Each item In Me.Repeater1.Items
If ((item.ItemType = ListItemType.Item) OrElse (item.ItemType = ListItemType.AlternatingItem)) Then
Dim label As Label = DirectCast(item.FindControl("LabelSubject"), Label)
Me.PlaceHolder1.Controls.Add(New LiteralControl(label.Text))
Enumerable.ToList(Of Control)((From c In Enumerable.Cast(Of Control)(item.Controls)
Where (c.GetType Is GetType(RadioButton))
Select c)).ForEach(Sub(c As Control)
Dim button As RadioButton = DirectCast(c, RadioButton)
If button.Checked Then
Dim tmpVar As Double = (Convert.ToDouble(button.ID.Substring((button.ID.Length - 2), 2)) / 10)
Me.PlaceHolder1.Controls.Add(New LiteralControl(String.Format(" = {0} คะแนน", tmpVar.ToString("0.0"))))
End If
End Sub)
Me.PlaceHolder1.Controls.Add(New LiteralControl("<br />"))
End If
Next
End Sub
|
 |
 |
 |
 |
Date :
2013-05-23 08:59:18 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้เป็นตัวอย่างเอาไปศึกษานะ
ครั้งหน้าไม่ให้โค้ดแล้วนะ
----- ที่ให้มานั้นมันก็เพียงพอแล้วครับ ผมสามารถเขียน ASP.NET ได้แล้วครับ (ปกติเขียนไม่ค่อยคล่องเท่าไหร่)
|
 |
 |
 |
 |
Date :
2013-05-23 09:15:55 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะที่ช่วยดูโค้ด vb ให้ ทำให้รู้เกี่ยวกับ vb ขึ้นมาอีกนิดหน่อย เช่น
1.
Code (VB.NET)
Where (r.GetType() = GetType(RadioButton))
' ควรจะใช้ is มากกว่า
Where (r.GetType() Is GetType(RadioButton))
แต่ของ c# ก็ใช้ == ตามเดิม
2 ทำให้รู้ว่า vb ก็ทำแบบนี้ได้
Code (VB.NET)
Enumerable.ToList(Of RadioButton)(From r In e.Item.Controls.Cast(Of Control)()
Where (r.GetType() Is GetType(RadioButton))
Select DirectCast(r, RadioButton)).ForEach(Sub(r)
r.GroupName = DirectCast(drv.Item("Code"), String)
End Sub)
ซึ่งต่างกับ c# ที่สามารถจะ .tolist() ได้เลย แต่ของ vb ของครอบด้วย Enumerable.ToList
3 เพิ่งรู้จักกับ andalso กับ orelse ของ vb
ปกติเขียน c# ใช้แค่ && กับ || ซึ่งมันก็คือ andalso กับ orelse อยู่แล้ว
นึกว่าใช้แค่ and กับ or
4 จะได้รู้ว่าถ้าจำเป็นต้องใช้ vb จริงๆ ค่อยเขียน vb เพราะโค้ดรกมาก ใช้ c# โค้ดดูสะอาดกว่าเยอะ
|
 |
 |
 |
 |
Date :
2013-05-23 11:02:23 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
2 ทำให้รู้ว่า vb ก็ทำแบบนี้ได้
C#
Code (C#)
(from c in);
VB.NET (2010)
Code (VB.NET)
'LINQ
Private Function GetRBCheck() As String
Return (From c In New RadioButton() {RadioButton1, RadioButton2, RadioButton3, RadioButton4} Where c.Checked Select c.Text).ToArray()(0)
End Function
4 จะได้รู้ว่าถ้าจำเป็นต้องใช้ vb จริงๆ ค่อยเขียน vb เพราะโค้ดรกมาก ใช้ c# โค้ดดูสะอาดกว่าเยอะ
ข้อแตกต่างระหว่าง VB & C# เปรียบเทียบให้เห็นชัดเจน
VB =ภรรยาของผม วันนี้อายุย่างเข้า 16 ปีครับ
C# = น้องเมียของผม วันนี้อายุย่างเข้า 13 ปีครับ
--- เพราะโค้ดรก(ดก)มากกว่า ใช้ c# โค้ดดูดกสะอาดกว่าเยอะ +55555
ข้อแตกต่างอีกอันหนึ่ง VB มี VBScript แต่ผมไม่เคยเห็น C#Script
|
 |
 |
 |
 |
Date :
2013-05-23 11:52:50 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีน่ะดีแล้ว เพราะใช้ javascript ได้
|
 |
 |
 |
 |
Date :
2013-05-23 12:05:00 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมสมมุติว่าผมตายไปแล้ว และผมให้คุณเลือกได้แค่ 1 คน (ภรรยาและน้องเมีย)
ถ้าคุณเลือกน้องเมียของผม มันก็ถูกต้องแล้วครับ
*****
แต่ว่า Poll.aspx แจ๋วจริงฯ มันทำให้ผมได้ไอเดียใหม่ฯ (ปกติผมใช้ GridView/Manual Table เป็นหลัก)
ซึ่งข้อจำกัดของมัน อทิเช่น Merge Column/Rows/Footer/etc ทำให้ผมหงุดหงิดน่ารำคาญ
ต่อไปผมคงต้องหันมาใช้งานเจ้า Repeater ให้มากขึ้น เรื่อง Paging คงไม่ใช่ประเด็นสำคัญอะไร
ผมอาจจะใช้ WebDyer มาใช้งานร่วมกันได้ (WebDyer Paging www.codeplex.com)
|
 |
 |
 |
 |
Date :
2013-05-23 12:16:44 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พูดจากใจจริงนะ ถ้าไม่จำเป็นจริงๆ จะไม่ใช้ repeater หรอก
เพราะไม่ชอบการใช้ find control ใช้แล้วเหมือนสิ้นคิดไงไม่รู้
พอดีเป็นคนเยอะไปนิดนึง
|
 |
 |
 |
 |
Date :
2013-05-23 12:37:51 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพียงแค่
อยากขอบคุณ หัวข้อกระทู้นี้ และผมได้นำความรู้ที่ได้ไปประยุกต์ใช้กับระบบงานจริงของผม
ตาราง เก็บสิทธิ์รวม

หน้าจอกำหนดสิทธิ์ ระดับผู้ใช้งาน

Code (VB.NET)
#Region "Repeater Manager"
'Thank : #095316 คุณ กำลังเครียด/คุณ ห้ามตอบเกินวันละ 2 กระทู้ (www.thaicreate.com)
Private Sub Repeater1_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
If ((e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem)) Then
Dim drv As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
Dim lblMenuName As Label = DirectCast(e.Item.FindControl("lblMenuName"), Label)
lblMenuName.Text = drv.Item("xTitleTH").ToString()
'***** Fixed Bug's Item.DataItem are all null when postback.
lblMenuName.Attributes.Add("MenuID", drv.Item("MenuID"))
'*****
Enumerable.ToList(Of Control)((From c In Enumerable.Cast(Of Control)(e.Item.Controls)
Where (c.GetType Is GetType(CheckBox))
Select c)).ForEach(Sub(c As Control)
Dim cb As CheckBox = DirectCast(c, CheckBox)
Try
cb.Checked = If(drv.Item("ACL").ToString().Substring(Convert.ToSByte(cb.ID.Substring(1)), 1) = "1", True, False)
Catch ex As Exception
cb.Checked = False
End Try
End Sub)
End If
End Sub
Protected Sub SaveData(sender As Object, e As EventArgs)
If cboUsers.SelectedValue = "-1" Then
'alert("Please select...");
Return
End If
'Dim strSQL() As String = {} '--> Array.Resize(strSQL, strSQL.Length + 1)
Dim strACL As String = String.Empty
Dim s As New StringBuilder()
s.Append("MERGE INTO msrFormPerm AS T ") 'Target
s.Append("USING ( VALUES ")
For Each item In Me.Repeater1.Items
strACL = String.Empty
If ((item.ItemType = ListItemType.Item) OrElse (item.ItemType = ListItemType.AlternatingItem)) Then
'Dim drv As DataRowView = DirectCast(item.DataItem, DataRowView) 'item.DataItem are all null
Dim lblMenuName As Label = DirectCast(item.FindControl("lblMenuName"), Label)
Enumerable.ToList(Of Control)((From c In Enumerable.Cast(Of Control)(item.Controls)
Where (c.GetType Is GetType(CheckBox))
Select c)).ForEach(Sub(c As Control)
strACL &= If(DirectCast(c, CheckBox).Checked, "1", "0")
End Sub)
s.Append("(999, ") 'Maybe Fixed Branch 999
s.Append(lblMenuName.Attributes.Item("MenuID") & ", ")
s.Append("0, ") '0 = Users ID, Otherwise is Group ID
s.Append(cboUsers.SelectedValue & ", ")
s.Append("'" & strACL & "'), ") 'Rem*****
End If
Next
s.Remove(s.Length - 2, 2) 'Remove End of Rem***** [,Space(1)]
s.Append(") AS S (BranchID, PageID, RoleID, UserID, ACL) ") 'Source
s.Append("ON T.BranchID = S.BranchID AND T.PageID = S.PageID AND T.RoleID = S.RoleID AND T.UserID = S.UserID ")
s.Append("WHEN MATCHED AND S.ACL = N'0000000000' THEN DELETE ")
s.Append("WHEN MATCHED THEN ")
s.Append("UPDATE SET ACL = S.ACL ")
s.Append("WHEN NOT MATCHED BY TARGET AND S.ACL <> N'0000000000' THEN ")
s.Append("INSERT (BranchID, PageID, RoleID, UserID, ACL) VALUES (S.BranchID, S.PageID, S.RoleID, S.UserID, S.ACL);")
'Execute(Query(s.ToString()))
End Sub
#End Region
|
 |
 |
 |
 |
Date :
2013-05-29 19:27:37 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|