|
![](/images/resource/spacer.gif) |
|
การใช้ Sessionในเอาออปเจ๊ค RadioButtonList การเขียนโค้ดยังไงครับขาดอยู่ตัวเดียว |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
สวัสดีครับ ผมอยากทราบการใช้ Session กับ Radiobuttonlist ครับ ค่าไม่ออกมา ทำการเชื่อมต่อกับ database เอาไว้ radio มีให้เลือกแต่พอเลือกแล้ว ค่าไม่ออกมา
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
private SqlConnection CN()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["AAA"].ToString();
return con;
}
DataSet ds;
string sql;
protected void Page_Load(object sender, EventArgs e)
{
sql = "select*from student";
SqlCommand cm = new SqlCommand(sql, CN());
ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, CN());
da.Fill(ds, "student");
DropDownList1.DataSource = ds.Tables["student"];
DropDownList1.DataTextField = "sname";
DropDownList1.DataValueField = "sname"; // ต้อวเป็น PK radio checkbox dropdownlist listbox
DropDownList1.DataBind();
RadioButtonList1.DataSource = ds.Tables["student"];
RadioButtonList1.DataTextField = "stel";
RadioButtonList1.DataValueField = "sname";
RadioButtonList1.DataBind();
Session["A"] = TextBox1.Text;
Session["B"] = TextBox2.Text;
Session["C"] = DropDownList1.SelectedItem.ToString();
Session["D"] = RadioButtonList1.SelectedItem.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Response.Redirect("default2.aspx?");
}
protected void Button2_Click(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Redirect("default2.aspx?");
}
}
รบกวนด้วยครับ ขอบคุณมากครับ
Tag : ASP, Ms SQL Server 2008, Web (ASP.NET), C#, Windows
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-04-23 20:18:36 |
By :
snowman0020 |
View :
728 |
Reply :
2 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
แบบนี้ไม่ได้ครับ เพราะตอนที่มัน PostBack มันก็ไปโหลดค่าเดิม ๆ ใหม่อีกครั้งครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
private SqlConnection CN()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["AAA"].ToString();
return con;
}
DataSet ds;
string sql;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindData();
}
}
protected void BindData()
{
sql = "select*from student";
SqlCommand cm = new SqlCommand(sql, CN());
ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, CN());
da.Fill(ds, "student");
DropDownList1.DataSource = ds.Tables["student"];
DropDownList1.DataTextField = "sname";
DropDownList1.DataValueField = "sname"; // ต้อวเป็น PK radio checkbox dropdownlist listbox
DropDownList1.DataBind();
RadioButtonList1.DataSource = ds.Tables["student"];
RadioButtonList1.DataTextField = "stel";
RadioButtonList1.DataValueField = "sname";
RadioButtonList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Response.Redirect("default2.aspx?");
}
protected void Button2_Click(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Session["A"] = TextBox1.Text;
Session["B"] = TextBox2.Text;
Session["C"] = DropDownList1.SelectedItem.ToString();
Session["D"] = RadioButtonList1.SelectedItem.ToString();
Response.Redirect("default2.aspx?");
}
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-04-24 10:15:24 |
By :
mr.win |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 02
|