|
 |
aspx thread: DataGrid 's OnEditCommand Event
Message #1 by =?gb2312?q?chun=20wang?= <c_wang_99@y...> on Tue, 6 Nov 2001 23:45:20 +0800 (CST)
|
|
Hi there;
when I triggered the OnEditCommand Event, the Event
handler function DataGrid_Edit raised. But I got
error:
line 0, Object Requested.
the problem should based on DataGridCommandEventArgs e
Object.Can anyone give some hints about it?
++++++++part of code++++++++++++
void DataGrid_Edit(Object o,DataGridCommandEventArgs
e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataSource = da.Tables[0].DefaultView;
DataGrid1.DataBind();
}
_________________________________________________________
Do You Yahoo!? 登录免费雅虎电邮! http://mail.yahoo.com.cn
<font color=#6666FF>无聊?郁闷?高兴?没理由?都来聊天吧!</font>——
雅虎全新聊天室! http://cn.chat.yahoo.com/c/roomlist.html
Message #2 by Scott Watermasysk <swatermasysk@C...> on Tue, 6 Nov 2001 11:02:40 -0500
|
|
You need to reload your data. You are setting the DataSource equal to
da.Tables[0].DefaultView, but you aren't putting anything into this
data
object.
Something like:
void BindData()
{
PTSDAL LoadData =3D new PTSDAL();
dt =3D LoadData.GetAllJobs();
dgViewJobs.DataSource =3D dt;
dgViewJobs.DataBind();
}
void Edit_Click(Object sender, DataGridCommandEventArgs e)
{
dgViewJobs.EditItemIndex =3D e.Item.ItemIndex;
BindData();
}
HTH,
Scott
p.s. If this doesn't help, submit more code.
-----Original Message-----
From: chun wang [mailto:c_wang_99@y...]
Sent: Tuesday, November 06, 2001 10:45 AM
To: ASP+
Subject: [aspx] DataGrid 's OnEditCommand Event
Hi there;
when I triggered the OnEditCommand Event, the Event
handler function DataGrid_Edit raised. But I got
error:
line 0, Object Requested.
the problem should based on DataGridCommandEventArgs e
Object.Can anyone give some hints about it?
++++++++part of code++++++++++++
void DataGrid_Edit(Object o,DataGridCommandEventArgs
e)
{
DataGrid1.EditItemIndex =3D e.Item.ItemIndex;
DataGrid1.DataSource =3D da.Tables[0].DefaultView;
DataGrid1.DataBind();
}
_________________________________________________________
Do You Yahoo!? =B5=C7=C2=BC=C3=E2=B7=D1=D1=C5=BB=A2=B5=E7=D3=CA!
http://mail.yahoo.com.cn
<font
color=3D#6666FF>=CE=DE=C1=C4=A3=BF=D3=F4=C3=C6=A3=BF=B8=DF=D0=CB=A3=BF=C3
=BB=C0=ED=D3=C9=A3=BF=B6=BC=C0=B4=C1=C4=CC=EC=B0=C9=A3=A1</font>=A1=AA=A1
=AA
=D1=C5=BB=A2=C8=AB=D0=C2=C1=C4=CC=EC=CA=D2!
http://cn.chat.yahoo.com/c/roomlist.html
---
VBug Winter Conference 2001
Open Forum: Dan Appleman will be hosting an open
forum at The .NET Developer's Conference on
29th November 2001. The session will give
developers the chance to discuss and question
Dan on his experience with the .NET environment.
Dan has been programming Visual Basic since the
alpha version 1.0. And with over 10 years
Visual Basic experience is well qualified to
help you on your road to being a .NET Guru.
http://www.vbug.co.uk/redirect.asp?url=3D39&id=3D17
---
You are currently subscribed to
aspx as: swatermasysk@c...
$subst('Email.Unsub')
Message #3 by =?gb2312?q?chun=20wang?= <c_wang_99@y...> on Wed, 7 Nov 2001 12:08:26 +0800 (CST)
|
|
hi Scott;
Thanks for your hint, but still not work
here is the whole code, you can alter
server="your SQL server name" and database="
your database" and change table name as well
then run this code, see it works or not?
=====code for datagrid's enevt handler====
<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<body>
<script language="c#" runat="server">
void Page_Load(Object Source, EventArgs E)
{
if(!Page.IsPostBack)
{
BindGrid();
}
}
void BindGrid()
{
string ConnStr="server=TDIT-
KB4GFSFP6U;uid=sa;pwd=;database=temp";
DataSet ds = new DataSet();
SqlConnection cn= new SqlConnection(ConnStr);
SqlDataAdapter da= new SqlDataAdapter("select *
from salary", cn);
da.Fill(ds,"test");
DataGrid1.DataSource=ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}
void My_Edit(Object o, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}
void My_Cancel(Object o, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
BindGrid();
}
void My_Update(Object o, DataGridCommandEventArgs e)
{
// need update command here
}
</script>
<asp:DataGrid id="DataGrid1" runat="server"
GridLines="none" CellSpacing=1 CellPadding=1
Align=center AutoGenerateColumns="False"
OnEditCommand="My_Edit"
OnUpdateCommand="My_Update"
OnCancelCommand="My_Cancel">
<HeaderStyle backcolor=green forecolor=red />
<ItemStyle backcolor=bisque
HorizontalAlign="center"/>
<AlternatingItemStyle backcolor=gray
HorizontalAlign="center" />
<Columns>
<asp:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
>
</asp:EditCommandColumn>
<asp:BoundColumn DataField="pID" ReadOnly=True
HeaderText="ID"/>
<asp:BoundColumn DataField="pname" ReadOnly=True
HeaderText="Name of Job"/>
<asp:BoundColumn DataField="salary"
HeaderText="rate per hour" />
</Columns>
</asp:DataGrid>
<center><asp:Calendar runat="server" /></center>
</body>
</html>
===========end of code============================
--- Scott Watermasysk
<swatermasysk@C...> 的正文:>
You need to reload your data. You are setting the
> DataSource equal to
> da.Tables[0].DefaultView, but you aren't putting
> anything into this data
> object.
>
> Something like:
> void BindData()
> {
> PTSDAL LoadData = new PTSDAL();
> dt = LoadData.GetAllJobs();
> dgViewJobs.DataSource = dt;
> dgViewJobs.DataBind();
> }
>
> void Edit_Click(Object sender,
> DataGridCommandEventArgs e)
> {
> dgViewJobs.EditItemIndex = e.Item.ItemIndex;
> BindData();
> }
>
> HTH,
> Scott
>
> p.s. If this doesn't help, submit more code.
>
> -----Original Message-----
> From: chun wang [mailto:c_wang_99@y...]
> Sent: Tuesday, November 06, 2001 10:45 AM
> To: ASP+
> Subject: [aspx] DataGrid 's OnEditCommand Event
>
>
> Hi there;
>
> when I triggered the OnEditCommand Event, the Event
> handler function DataGrid_Edit raised. But I got
> error:
> line 0, Object Requested.
> the problem should based on DataGridCommandEventArgs
> e
> Object.Can anyone give some hints about it?
>
> ++++++++part of code++++++++++++
> void DataGrid_Edit(Object o,DataGridCommandEventArgs
> e)
> {
> DataGrid1.EditItemIndex = e.Item.ItemIndex;
> DataGrid1.DataSource = da.Tables[0].DefaultView;
> DataGrid1.DataBind();
> }
>
>
_________________________________________________________
> Do You Yahoo!? 登录免费雅虎电邮!
> http://mail.yahoo.com.cn
>
> <font
>
color=#6666FF>无聊?郁闷?高兴?没理由?都来聊天吧!</font>——
>
> 雅虎全新聊天室!
> http://cn.chat.yahoo.com/c/roomlist.html
>
> ---
> VBug Winter Conference 2001
>
> Open Forum: Dan Appleman will be hosting an open
> forum at The .NET Developer's Conference on
> 29th November 2001. The session will give
> developers the chance to discuss and question
> Dan on his experience with the .NET environment.
> Dan has been programming Visual Basic since the
> alpha version 1.0. And with over 10 years
> Visual Basic experience is well qualified to
> help you on your road to being a .NET Guru.
>
> http://www.vbug.co.uk/redirect.asp?url=39&id=17
>
> ---
> You are currently subscribed to
> aspx as: swatermasysk@c...
> $subst('Email.Unsub')
>
> ---
> VBug Winter Conference 2001
>
> Open Forum: Dan Appleman will be hosting an open
> forum at The .NET Developer's Conference on
> 29th November 2001. The session will give
> developers the chance to discuss and question
> Dan on his experience with the .NET environment.
> Dan has been programming Visual Basic since the
> alpha version 1.0. And with over 10 years
> Visual Basic experience is well qualified to
> help you on your road to being a .NET Guru.
>
> http://www.vbug.co.uk/redirect.asp?url=39&id=17
>
> ---
> You are currently subscribed to
> aspx as: c_wang_99@y...
> $subst('Email.Unsub')
_________________________________________________________
Do You Yahoo!? 登录免费雅虎电邮! http://mail.yahoo.com.cn
<font color=#6666FF>无聊?郁闷?高兴?没理由?都来聊天吧!</font>——
雅虎全新聊天室! http://cn.chat.yahoo.com/c/roomlist.html
|
|
 |