|
|
|
ช่วยหน่อยค่ะ ต้องการส่งค่าไปแสดงอีกหน้านึงค่ะ ช่วยดูหน่อยค่ะว่าเขียนถูกไหม asp.net c# |
|
|
|
|
|
|
|
ทำแล้วค่ะ แต่ของดิฉันก็ยังไม่ได้ก็เลยลองเปลี่ยนมาทำ แบบนี้
หน้า Default.aspx
<asp:GridView ID="GridView1" runat="server" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:ButtonField CommandName="see1" HeaderText="ลำดับ" DataTextField="id" />
<asp:ButtonField CommandName="see1" HeaderText="ชื่อ" DataTextField="name" />
</Columns>
หน้า Default.aspx.cs
rotected void Page_Load(object sender, EventArgs e)
{
string StrConn = WebConfigurationManager.ConnectionStrings["DD"].ToString();
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
string sqlProduct;
sqlProduct = " SELECT * FROM student WHERE id ='" + TextBox1.Text + "' ";
SqlDataAdapter da = new SqlDataAdapter(sqlProduct, Conn);
DataSet ds = new DataSet();
da.Fill(ds, "student");
GridView1.DataSource = ds.Tables["student"];
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex1 = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "see1")
{
String id1_1 = GridView1.Rows[rowIndex1].Cells[0].Text;
Session["sent1"] = id1_1;
String id1_2 = GridView1.Rows[rowIndex1].Cells[1].Text;
Session["sent2"] = id1_2;
Response.Redirect("Default2.aspx");
}
}
ค่ะ แต่หน้าที่รับข้อมูลก็ไม่แสดงค่า ไม่รู้ว่าเขียนอะไรผิด
หน้า Default2.aspx.cs
Label1.Text = Session["sent1"].ToString();
Label2.Text = Session["sent2"].ToString();
ช่วยหน่อยนะคะ ลองทำหลายวิธีค่าก็ไม่ยอมไปแสดงหน้าDefault2.aspx ซักที
|
|
|
|
|
Date :
2011-03-29 15:28:19 |
By :
mushroomsn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
//*** Hyperlink ***//
Label hplEdit = (HyperLink)(e.Row.FindControl("hplEdit"));
if (hplEdit != null)
{
hplEdit.Text = "Edit";
hplEdit.NavigateUrl = "WebPage.aspx?CustomerID=" + (string)DataBinder.Eval(e.Row.DataItem, "CustomerID");
}
Code เต็ม ๆ ครับ
Code (C#)
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
OleDbConnection objConn;
OleDbCommand objCmd;
void Page_Load(object sender,EventArgs e)
{
String strConnString;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("database/mydatabase.mdb") + ";";
objConn = new OleDbConnection(strConnString);
objConn.Open();
BindData();
}
void BindData()
{
String strSQL;
strSQL = "SELECT * FROM customer";
OleDbDataReader dtReader;
objCmd = new OleDbCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
//*** BindData to GridView ***//
myGridView.DataSource = dtReader;
myGridView.DataBind();
dtReader.Close();
dtReader = null;
}
void Page_UnLoad()
{
objConn.Close();
objConn = null;
}
void myGridView_RowDataBound(Object s, GridViewRowEventArgs e)
{
//*** CustomerID ***//
Label lblCustomerID = (Label)(e.Row.FindControl("lblCustomerID"));
if (lblCustomerID != null)
{
lblCustomerID.Text = (string)DataBinder.Eval(e.Row.DataItem, "CustomerID");
}
//*** Email ***//
Label lblName = (Label)(e.Row.FindControl("lblName"));
if (lblName != null)
{
lblName.Text = (string)DataBinder.Eval(e.Row.DataItem, "Name");
}
//*** Name ***//
Label lblEmail = (Label)(e.Row.FindControl("lblEmail"));
if (lblEmail != null)
{
lblEmail.Text = (string)DataBinder.Eval(e.Row.DataItem, "Email");
}
//*** CountryCode ***//
Label lblCountryCode = (Label)(e.Row.FindControl("lblCountryCode"));
if (lblCountryCode != null)
{
lblCountryCode.Text = (string)DataBinder.Eval(e.Row.DataItem, "CountryCode");
}
//*** Budget ***//
Label lblBudget = (Label)(e.Row.FindControl("lblBudget"));
if (lblBudget != null)
{
lblBudget.Text = DataBinder.Eval(e.Row.DataItem, "Budget").ToString();
}
//*** Used ***//
Label lblUsed = (Label)(e.Row.FindControl("lblUsed"));
if (lblUsed != null)
{
lblUsed.Text = DataBinder.Eval(e.Row.DataItem, "Used").ToString();
}
//*** Hyperlink ***//
Label hplEdit = (HyperLink)(e.Row.FindControl("hplEdit"));
if (hplEdit != null)
{
hplEdit.Text = "Edit";
hplEdit.NavigateUrl = "WebPage.aspx?CustomerID=" + (string)DataBinder.Eval(e.Row.DataItem, "CustomerID");
}
}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False"
onRowDataBound="myGridView_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="CustomerID">
<ItemTemplate>
<asp:Label id="lblCustomerID" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label id="lblName" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label id="lblEmail" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CountryCode">
<ItemTemplate>
<asp:Label id="lblCountryCode" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget">
<ItemTemplate>
<asp:Label id="lblBudget" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Used">
<ItemTemplate>
<asp:Label id="lblUsed" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Hyperlink id="hplEdit" runat="server"></asp:Hyperlink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
|
|
|
|
|
Date :
2011-03-29 21:45:18 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณนะคะ ขอบคุณที่ช่วยเหลือคะ
|
|
|
|
|
Date :
2011-03-30 14:01:55 |
By :
mushroomsn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|