 |
|
ผมต้องการให้เวลาเปิดเว็บขึ้นมาให้ RadioButton มีการเช็ค ตามเงี่อนไข ใครรู้วิธีช่วยบอกหน่อย |
|
 |
|
|
 |
 |
|
ทดลองสร้าง Page ตามตัวอย่างข้างล่างนี้ดูครับ
Code (C#)
public partial class _Default : System.Web.UI.Page
{
// Class RadioData สร้างเพื่อเอาไว้กำหนดให้กับ RadioButton
public class RadioData
{
public string Name { get; set; }
public int Value { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// สร้าง Class รับค่าเพื่อกำหนดให้กำ RadioButtonList
List<RadioData> list = new List<RadioData>()
{
new RadioData() { Name = "ไม่ใช่", Value = 0 },
new RadioData() { Name = "ใช่", Value = 1 },
};
RadioButtonList1.DataSource = list;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Value";
RadioButtonList1.DataBind();
// สมมุติดึงค่ามาจากฐานข้อมูล ลองแก้ให้เป็น 0 หรือ 1 ดูนะครับ
int star = 1;
RadioButtonList1.SelectedValue = (star == 0 ? "0" : "1");
}
}
}
กำหนดแบบ Dynamic Order ให้กับ Radio Button แต่เข้าใจว่า จากหน้าจอ จขกท. ต้องสร้าง RadioButtonList ขึ้นมา 2 ชุดนะครับ เพราะว่าสถานะแต้ม กับสถานะแต้มดาว อยู่คนละ Order กัน แต่จากตัวอย่างข้างบน ผมสร้างให้ดูเพียงชุดเดียวนะครับ ไป Apply ต่อเอาเองครับ ไม่ยากแล้วครับ
|
 |
 |
 |
 |
Date :
2014-05-08 22:06:55 |
By :
gunnermontana |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้าวเขียนด้วย VB ลืมดูไปครับ ลองดูตาม Code ด้านล่างครับ
Code (VB.NET)
Public Class Default
Inherits System.Web.UI.Page
' Class RadioData สร้างเพื่อเอาไว้กำหนดให้กับ RadioButton
Public Class RadioData
Private m_Name As String
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_Value As Integer
Public Property Value() As Integer
Get
Return m_Value
End Get
Set(value As Integer)
m_Value = value
End Set
End Property
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' สร้าง Class รับค่าเพื่อกำหนดให้กำ RadioButtonList
Dim list As New List(Of RadioData)() From { _
New RadioData() With { _
.Name = "ไม่ใช่", _
.Value = 0 _
}, _
New RadioData() With { _
.Name = "ใช่", _
.Value = 1 _
} _
}
RadioButtonList1.DataSource = list
RadioButtonList1.DataTextField = "Name"
RadioButtonList1.DataValueField = "Value"
RadioButtonList1.DataBind()
' สมมุติดึงค่ามาจากฐานข้อมูล ลองแก้ให้เป็น 0 หรือ 1 ดูนะครับ
Dim star As Integer = 1
RadioButtonList1.SelectedValue = If(star = 0, "0", "1")
End If
End Sub
End Class
|
 |
 |
 |
 |
Date :
2014-05-08 22:16:58 |
By :
gunnermontana |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
RadioButtonList1.DataSource = (With {Key .Yes= "1", .No = "0"},
{Key .Yes= "1", .No = "0" ).ToList()
|
 |
 |
 |
 |
Date :
2014-05-09 15:25:18 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ ครับพี่ๆ   
ได้แล้วครับ
|
 |
 |
 |
 |
Date :
2014-05-10 10:22:12 |
By :
sununrak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีเทพ สิงสถิตกันเยอะนะครับ หุๆ 
|
 |
 |
 |
 |
Date :
2014-05-10 11:04:20 |
By :
nongpaoza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|