Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ช่วยหน่อยค่ะ ต้องการส่งค่าไปแสดงอีกหน้านึงค่ะ ช่วยดูหน่อยค่ะว่าเขียนถูกไหม asp.net c#



 

ช่วยหน่อยค่ะ ต้องการส่งค่าไปแสดงอีกหน้านึงค่ะ ช่วยดูหน่อยค่ะว่าเขียนถูกไหม asp.net c#

 



Topic : 057989



โพสกระทู้ ( 301 )
บทความ ( 0 )



สถานะออฟไลน์




หน้า Default5.aspx

Code (C#)
<a href ="get5.aspx?iddog=<%# Eval("iddog") %> ">

                    <asp:GridView ID="GridView1" runat="server"  >
                    </asp:GridView>


ส่งข้อมูลใน Girdview ไปอีกหน้าค่ะ

Default5.aspx.cs
Code (C#)
string StrConn = WebConfigurationManager.ConnectionStrings["Database"].ToString();
        SqlConnection Conn = new SqlConnection(StrConn);
        Conn.Open();
        string sqlProduct;
        sqlProduct = " SELECT  iddog,namedog FROM dog WHERE  (iddog between  '" + TextBox1.Text + "' and '" + TextBox3.Text + "' ) OR  namedog  ='" + TextBox2.Text + "' ";
       
        SqlDataAdapter da = new SqlDataAdapter(sqlProduct, Conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "dog");
        GridView1.DataSource = ds.Tables["dog"];
        GridView1.DataBind();


หน้าที่รับข้อมูลมาโชว์ get5.aspx
this.Label1.Text = Request.QueryString["iddog"];

มันไม่สามารถคลิกข้อมูลได้ ตั้งแต่หน้า Default5.aspx ค่ะ
ไม่รู้จะ href ตรงไหนของ Code ดีค่ะ



Tag : .NET, Ms SQL Server 2005, Ms SQL Server 2008, C#







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-03-29 11:31:19 By : mushroomsn View : 1340 Reply : 5
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ถ้าใน GridView ทำใน FindControl ก้ได้ครับ

Go to : (C#) ASP.NET GridView Control - FindControl

Go to : (C#) ASP.NET SQL Server Edit/Update Record






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-29 12:09:05 By : webmaster
 


 

No. 2



โพสกระทู้ ( 301 )
บทความ ( 0 )



สถานะออฟไลน์


ทำแล้วค่ะ แต่ของดิฉันก็ยังไม่ได้ก็เลยลองเปลี่ยนมาทำ แบบนี้
หน้า 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
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Go to : (C#) ASP.NET SQL Server Edit/Update Record

ตัวอย่างนี้ใช้ Repeater ครับ แต่ถ้าจะเปลี่ยนเป็น GridView ก็ไม่ยากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-29 21:03:27 By : webmaster
 


 

No. 4



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

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
 


 

No. 5



โพสกระทู้ ( 301 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณนะคะ ขอบคุณที่ช่วยเหลือคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-30 14:01:55 By : mushroomsn
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยค่ะ ต้องการส่งค่าไปแสดงอีกหน้านึงค่ะ ช่วยดูหน่อยค่ะว่าเขียนถูกไหม asp.net c#
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่