|
|
|
ถามเกี่ยวกับ gridview ครับ อยากให้กดบันทึกแล้วข้อมูลในตาราง gridview refresh อ่ะครับ |
|
|
|
|
|
|
|
จริงๆก็ศึกษาจากหลายๆกระทู้แล้วนะครับ แต่ไม่เข้าใจเพราะพื้นฐานมีน้อยมากกกกครับ
addroom.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addroom.aspx.cs" Inherits="roommanage.addroom" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.8.12.custom.css"/>
<style type="text/css">
/* Overide css code กำหนดความกว้างของปฏิทินและอื่นๆ */
.ui-datepicker{
width:210px;
font-family:tahoma;
font-size:11px;
text-align:center;
}
.style1
{
width: 91px;
}
.style2
{
width: 226px;
}
</style>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<!-- header -->
<div id="top">
<div id="name"><a href="#">Kasetsart University</a></div>
<div id="split"></div>
<div style="border-top:6px solid #7abb37; background-color:blue; ">
<div id="slogan"> มหาวิทยาลัยเกษตรศาสตร์ วิทยาเขตศรีราชา</div>
<div id="contact_us"><a href="#">Sitemap</a></div>
</div>
</div>
<div id="logo">
<div id="logo_text">
Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Pellentesque lobortis nibh
eu mauris. Morbi arcu tortor, auctor et,
facilisis nec, egestas sit amet, enim.
</div>
<div id="menu">
<a href="default.aspx">หน้าแรก</a>|
<a href="room.aspx">ระบบจองห้องเรียน</a>|
<a href="#">Services</a>|
<a href="#">Pricing</a>|
<a href="#">Contacts</a>
</div>
</div>
<!--end header -->
<!-- main -->
<div style="background-color:White;">
<table><tr>
<td valign="top" align="left" style="width:250px;"><div>
<asp:Panel ID="pnLOGIN" runat="server" Visible="False">
<table>
<tr>
<td align="left">บัญชีผู้ใช้:</td><td><asp:Label ID="lblLOGIN" runat="server" Text="Label"></asp:Label></td>
<td align="left">
<asp:Button ID="cmdLOGOUT" runat="server" Text="ออกจากระบบ" onclick="cmdLOGOUT_Click" /></td>
</tr>
</table>
</asp:Panel>
</div></td>
<td style="width:1000px;">
<div>
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.12.custom.min.js"></script>
<script type="text/javascript" src="js/datepicker.js"></script>
<script type="text/javascript">
$(function () {
setminDate("+0d"); //กำหนดจำนวนวัน ก่อนวันปัจจุบัน
setDatepicker("#dateInput");
});
function dateInput_onclick() {
}
</script>
เพิ่มข้อมูลห้องเรียน</div>
<table border="1">
<tr>
<td class="style1">
ชื่อห้อง :
</td>
<td class="style2">
<asp:TextBox ID="txtROOM" runat="server" style="margin-left: 0px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
จำนวนที่นั่ง:</td>
<td class="style2">
<asp:TextBox ID="txtNUM" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1" valign="top">
ประเภท:</td>
<td class="style2">
<asp:RadioButtonList ID="rdoTYPE" runat="server">
<asp:ListItem Selected="True">บรรยาย</asp:ListItem>
<asp:ListItem>ปฏิบัติการ</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr><td colspan="2" align="center">
<asp:Button ID="cmdSAVE" runat="server" Text="บันทึก" onclick="cmdSAVE_Click" />
<input type="reset" id="cmdRESET" value="ยกเลิก" />
</td></tr>
<tr><td colspan="2" align="center">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:project_roomConnectionString3 %>"
SelectCommand="SELECT [name_room], [num_chair], [type] FROM [room_detail]"
ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [room_detail] WHERE [name_room] = @original_name_room AND (([num_chair] = @original_num_chair) OR ([num_chair] IS NULL AND @original_num_chair IS NULL)) AND (([type] = @original_type) OR ([type] IS NULL AND @original_type IS NULL))"
InsertCommand="INSERT INTO [room_detail] ([name_room], [num_chair], [type]) VALUES (@name_room, @num_chair, @type)"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [room_detail] SET [num_chair] = @num_chair, [type] = @type WHERE [name_room] = @original_name_room AND (([num_chair] = @original_num_chair) OR ([num_chair] IS NULL AND @original_num_chair IS NULL)) AND (([type] = @original_type) OR ([type] IS NULL AND @original_type IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_name_room" Type="String" />
<asp:Parameter Name="original_num_chair" Type="String" />
<asp:Parameter Name="original_type" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="name_room" Type="String" />
<asp:Parameter Name="num_chair" Type="String" />
<asp:Parameter Name="type" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="num_chair" Type="String" />
<asp:Parameter Name="type" Type="String" />
<asp:Parameter Name="original_name_room" Type="String" />
<asp:Parameter Name="original_num_chair" Type="String" />
<asp:Parameter Name="original_type" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="name_room" HeaderText="ชื่อห้อง"
SortExpression="name_room" />
<asp:BoundField DataField="num_chair" HeaderText="จำนวนที่นั่ง"
SortExpression="num_chair" />
<asp:BoundField DataField="type" HeaderText="ประเภท" SortExpression="type" />
<asp:CommandField ShowEditButton="True" HeaderText="แก้ไข" />
<asp:CommandField ShowDeleteButton="True" HeaderText="ลบ" />
</Columns>
</asp:GridView>
<br />
</td></tr>
</table>
</td>
</tr></table>
</div>
<div id="footer">
<div id="right_footer">
</div>
</div>
</form>
</body>
</html>
addroom.aspx.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Security;
namespace roommanage
{
public partial class addroom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["LoginName"] != null)
{
pnLOGIN.Visible = true;
lblLOGIN.Text = Convert.ToString(Session["LoginName"]);
}
else
{
pnLOGIN.Visible = false;
Response.Redirect("default.aspx");
}
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
}
protected void cmdLOGOUT_Click(object sender, EventArgs e)
{
if (Session["LoginName"] != null)
{
Session.Abandon();
Response.Redirect("default.aspx");
}
}
protected void cmdSAVE_Click(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
String strConnString, strSQL;
string room, num, typeRoom;
room = this.txtROOM.Text.Trim();
num = this.txtNUM.Text.Trim();
typeRoom = this.rdoTYPE.Text;
strConnString = "Server=WPEE-PC\\SA; UID=sa;PASSWORD=1q2w3e4r;DATABASE=project_room;MAX Pool Size=400; Connect Timeout=600;";
strSQL = "INSERT INTO room_detail (name_room,num_chair,type) " +
" VALUES " +
" ('" + room + "','" + num + "','" + typeRoom + "')";
objConn.ConnectionString = strConnString;
objConn.Open();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
}
}
}
Tag : ASP.NET, Ms SQL Server 2008, Web (ASP.NET), C#
|
ประวัติการแก้ไข 2011-08-19 02:32:56
|
|
|
|
|
Date :
2011-08-19 02:25:43 |
By :
wpeeIT |
View :
1331 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าอยากให้ Refresh หลังจากที่ Save แล้วจะต้อง BindData ให้ GridView ใหม่ครับ
|
|
|
|
|
Date :
2011-08-19 06:24:29 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใส่ BindData ที่ตำแหน่งไหนหรอครับ พอจะมีคำแนะนำเพิ่มเติมมั๊ยครับ
ขอบคุณครับ
|
|
|
|
|
Date :
2011-08-19 13:03:13 |
By :
wpeeIT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับขอบคุณมากๆๆเลยครับ
|
|
|
|
|
Date :
2011-08-20 22:43:33 |
By :
wpeeIT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|