|
 |
|
ส่งค่าข้ามไปอีกฟอร์ม จาก gridview ครับ ?? ทำยังไงครับ ?? web app |
|
 |
|
|
 |
 |
|
ส่งค่าข้ามไปอีกฟอร์ม จาก gridview ครับ ?? ทำยังไงครับ ?? web app
โดยจะให้เอาค่าจากที่เลือกใน checkbox ไปแสดงในอีก ฟอร์มนึงครับ
Code (C#)
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataReader dtReader;
String strSQL;
void Page_Load(object sender,EventArgs e)
{
String strConnString;
strConnString = "Server=localhost;UID=sa;PASSWORD=12345;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
objConn = new SqlConnection(strConnString);
objConn.Open();
if(!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
String strSQL;
strSQL = "SELECT FullName,Position FROM Register UNION SELECT BossName,BossPosition FROM Boss";
SqlDataReader dtReader;
objCmd = new SqlCommand(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)
{
Label lblBossName = (Label)(e.Row.FindControl("lblBossName"));
if (lblBossName != null)
{
lblBossName.Text = (string)DataBinder.Eval(e.Row.DataItem, "FullName");
}
Label lblBossPosition = (Label)(e.Row.FindControl("lblBossPosition"));
if (lblBossPosition != null)
{
lblBossPosition.Text = (string)DataBinder.Eval(e.Row.DataItem, "Position");
}
}
void Button1_Click(object sender,EventArgs e)
{
CheckBox chkBossName;
Label lblBossName;
int i;
lblText.Text = "";
for( i = 0; i <= myGridView.Rows.Count - 1; i++)
{
chkBossName = (CheckBox)myGridView.Rows[i].FindControl("chkBossName");
lblBossName = (Label)myGridView.Rows[i].FindControl("lblBossName");
if (chkBossName.Checked)
{
this.lblText.Text = this.lblText.Text + "<br>" + lblBossName.Text;
}
}
}
</script>
<body>
<form id="form1" runat="server">
<div style="font-weight: 700; font-size: large">
เพิ่มผู้เข้ารวมประชุม<br />
</div>
<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False"
onRowDataBound="myGridView_RowDataBound"
style="text-align: left; margin-top: 15px;" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
Height="156px" Width="54%">
<Columns>
<asp:TemplateField HeaderText="เลือก">
<ItemTemplate>
<asp:CheckBox id="chkBossName" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ชื่อ - นามสกุล">
<ItemTemplate>
<asp:Label id="lblBossName" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ตำแหน่ง">
<ItemTemplate>
<asp:Label id="lblBossPosition" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
<br />
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Submit"></asp:Button>
<br />
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), C#

|
|
 |
 |
 |
 |
Date :
2012-12-25 15:51:15 |
By :
Kaen17 |
View :
1608 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะเอาค่าไปทำอะไรครับ ส่งผ่านพวก QueryString , Session ก็ได้ครับ
|
 |
 |
 |
 |
Date :
2012-12-25 16:14:37 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|