|
|
|
Error ช่วยหน่อยจร้า บอกหน่อยได้มั๊ยบอกฉันหน่อยนะครับบ |
|
|
|
|
|
|
|
พอดีทำ search detail view ได้แล้วจะเพิ่มให้มัน แก้ไข ได้แต่มัน error
Page load
Code (ASP)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace tet
{
public partial class WebForm3 : System.Web.UI.Page
{
String strKeyWord;
protected void Page_Load(object sender, EventArgs e)
{
strKeyWord = this.txtKeyWord.Text;
}
protected void BindData()
{
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataAdapter dtAdapter = new SqlDataAdapter();
DataSet ds = new DataSet();
String strConnString, strSQL;
string connection = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
strSQL = "SELECT * FROM student WHERE (id_student like '%" + strKeyWord + "%' OR name_student like '%" + strKeyWord + "%') ";
objConn.ConnectionString = connection;
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
dtAdapter.SelectCommand = objCmd;
dtAdapter.Fill(ds);
//*** BindData to GridView ***//
myDetailsView.DataSource = ds;
myDetailsView.DataBind();
dtAdapter = null;
objConn.Close();
objConn = null;
}
protected void myDetailsView_DataBound(Object sender, System.EventArgs e)
{
//*** CustomerID ***//
Label lblstuid = (Label)(myDetailsView.FindControl("lblstuid"));
if (lblstuid != null)
{
lblstuid.Text = (string)DataBinder.Eval(myDetailsView.DataItem, "id_student");
}
//*** Email ***//
Label lblNamestu = (Label)(myDetailsView.FindControl("lblNamestu"));
if (lblNamestu != null)
{
lblNamestu.Text = (string)DataBinder.Eval(myDetailsView.DataItem, "name_student");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
BindData();
}
// update
protected void myDetailsView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
{
switch (e.NewMode)
{
case DetailsViewMode.Edit:
myDetailsView.ChangeMode(DetailsViewMode.Edit);
break;
case DetailsViewMode.ReadOnly:
myDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
break;
}
BindData();
}
protected void myDetailsView_ItemUpdating(Object sender, DetailsViewUpdatedEventArgs e)
{
TextBox txtstuid = (TextBox)(myDetailsView.FindControl("txteditstuid"));
TextBox txtnamestu = (TextBox)(myDetailsView.FindControl("txteditnamestu"));
}
}
}
html page
Code (ASP)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtKeyWord" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server" Text="Button" onclick="Button1_Click" />
<div>
<asp:DetailsView id="myDetailsView" runat="server" AutoGenerateRows="false"
OnDataBound="myDetailsView_DataBound" Width="131px"
OnModeChanged="myDetailsView_ModeChanged"
OnItemUpdating="myDetailsView_ItemUpdating" >
<Fields>
<asp:TemplateField HeaderText="idstu">
<ItemTemplate>
<asp:Label id="lblstuid" runat="server" Text='<% DataBinder.Eval(Container, "DataItem.id_student) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtstuid" runat="server" Text='<%DataBinder.Eval(Container, "Dataitem.id_student) %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Namestu">
<ItemTemplate>
<asp:Label id="lblNamestu" runat="server" Text='<% DataBinder.Eval(Container, "DataItem.name_student) %>'></asp:Label>
<asp:TextBox ID="txtnamestu" runat="server" Text='<%DataBinder.Eval(Container, "Dataitem.name_student) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2010-08-07 16:22:41 |
By :
omisuka |
View :
1061 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<asp:DetailsView id="myDetailsView" runat="server" AutoGenerateRows="false"
OnDataBound="myDetailsView_DataBound" Width="131px"
OnModeChanged="myDetailsView_ModeChanged"
OnItemUpdating="myDetailsView_ItemUpdating" >
Code (C#)
protected void myDetailsView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
{
switch (e.NewMode)
{
case DetailsViewMode.Edit:
myDetailsView.ChangeMode(DetailsViewMode.Edit);
break;
case DetailsViewMode.ReadOnly:
myDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
break;
}
BindData();
}
|
ประวัติการแก้ไข 2010-08-07 17:01:37
|
|
|
|
Date :
2010-08-07 16:59:43 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้อะพี่ ToT error เหมือนเคย
|
|
|
|
|
Date :
2010-08-07 17:14:36 |
By :
omisuka |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมไม่ได้แก้ให้ แค่ให้ดูว่าทำไม error
|
|
|
|
|
Date :
2010-08-07 17:22:17 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|