菜鸟问题:DataGrid的事件不起作用(100分)

  • 主题发起人 主题发起人 dxb47
  • 开始时间 开始时间
D

dxb47

Unregistered / Unconfirmed
GUEST, unregistred user!
在下面的程序中,点击下一页没有反应,不知是怎么回事?
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<%@ Page Language="C#" Debug="true" %>
<script language="c#" runat="server">
//OleDbConnection cn ;
SqlConnection cn1;
protected void Page_Load(Object Src, EventArgs E)
{
// cn=new OleDbConnection("Provider=SQLOLEDB;Server=dxb2003;Database=test;Uid=sa;Pwd=040610");
cn1=new SqlConnection("Data Source=dxb2003;Initial Catalog=test;User ID=sa;Password=040610;");
if (!IsPostBack) BindGrid();
}
public void Add_Click(Object sender,EventArgs E)
{

String strSQL="insert into goods(code,name,jldw,jg) values (@code,@name,@jldw,@jg)";


SqlCommand cm=new SqlCommand(strSQL,cn1);;

cm.Parameters.Add(new SqlParameter("@code",SqlDbType.VarChar,32));
cm.Parameters["@code"].Value=Code.Text;
cm.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,64));
cm.Parameters["@name"].Value = Name.Text;
cm.Parameters.Add(new SqlParameter("@jldw",SqlDbType.VarChar,50));
cm.Parameters["@jldw"].Value = jldw.Text;
cm.Parameters.Add(new SqlParameter("@jg",SqlDbType.Money));
cm.Parameters["@jg"].Value = jg.Text;

cm.Connection.Open();
try
{
cm.ExecuteNonQuery();
Message.InnerHtml="<b>添加成功</b>";
}
catch (SqlException)
{
Message.InnerHtml="添加失败";
Message.Style["color"]="red";
}
cm.Connection.Close();
BindGrid();
}
void DataGrid_Page(Object sender , DataGridPageChangedEventArgs E)
{
dgGoods.CurrentPageIndex = E.NewPageIndex;
BindGrid();
}
void DataGrid_Edit(Object sender , DataGridCommandEventArgs E)
{
dgGoods.EditItemIndex=(int)E.Item.ItemIndex;
BindGrid();
}
void DataGrid_Cancel(Object sender,DataGridCommandEventArgs e)
{
}
void DataGrid_Update(Object sender,DataGridCommandEventArgs e)
{
}
void DataGrid_Delete(Object sender,DataGridCommandEventArgs e)
{
}
public void BindGrid()
{
SqlDataAdapter da=new SqlDataAdapter("select * from goods order by code",cn1);
DataSet ds = new DataSet();
da.Fill(ds);
dgGoods.DataSource=ds;
dgGoods.DataBind();
}
</script>
<body>
<form runat="server">
<table width="95%">
<tr><td valign="top">
<asp:DataGrid id="dgGoods" runat="server"
AllowPaging="True" PageSize="10"
Width="400" BackColor="#ccccff"
BorderColor="black" ShowFooter="false"
CellPadding=3 CellSpacing="0"
Font-Name="Verdana" Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
OnEditCommand="DataGrid_Edit"
OnCancelCommand="DataGrid_Cancel"
OnUpdateCommand="DataGrid_Update"
OnDeleteCommand="DataGrid_Delete"
OnPageIndexChanged="DataGrid_Page"
DataKeyField="Code"
AutoGenerateColumns="false"
MaintainState="false"
>
<PagerStyle Mode = "NextPrev" HorizontalAlign="Right" PrevPageText="上一页" NextPageText="下一页">
</PagerStyle>
<Columns>
<asp:EditCommandColumn EditText="编辑" CancelText="取消" UpdateText="更新" ItemStyle-Wrap="false"/>
<asp:ButtonColumn Text="删除" CommandName="Delete" ItemStyle-Wrap="false"/>
<asp:BoundColumn HeaderText="产品编码" DataField="Code" />
<asp:BoundColumn HeaderText="产品名称" DataField="Name" />
<asp:BoundColumn HeaderText="计量单位" DataField="jldw" />
<asp:BoundColumn HeaderText="产品单价" DataField="jg"
DataFormatString="{0:c}" />
</Columns>
</asp:DataGrid>
</td>

<td valign="top">
<table style="font: 8pt verdana">
<tr><td colspan="2" bgcolor="#aaaadd" style="font:10pt verdana">
添加新的产品
</td></tr>
<tr>
<td nowrap>产品编码:</td>
<td><asp:TextBox id="Code" runat="server" />
<asp:RequiredFieldValidator id="RFV1"
ControlTOValidate="Code"
Display="dynamic" runat="server">*
</asp:RequiredFieldValidator>
</td></tr>
<tr>
<td nowrap>产品名称:</td>
<td><asp:TextBox id="Name" runat="server" />
<asp:RequiredFieldValidator id="RFV2"
ControlTOValidate="Name"
Display="dynamic" runat="server">*
</asp:RequiredFieldValidator>
</td></tr>
<tr>
<td nowrap>计量单位:</td>
<td><asp:TextBox id="jldw" runat="server" />
<asp:RequiredFieldValidator id="RFV3"
ControlTOValidate="jldw"
Display="dynamic" runat="server">*
</asp:RequiredFieldValidator>
</td></tr>
<tr>
<td nowrap>产品单价:</td>
<td><asp:TextBox id="jg" runat="server" />
<asp:RequiredFieldValidator id="RFV4"
ControlTOValidate="jg"
Display="dynamic" runat="server">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td colspan="2" style="padding-top:15" align="center">
<asp:Button text="添加" OnClick="Add_Click" runat="server" />
</td></tr>
<tr><td colspan="2" style="padding-top:15" align="center">
<span id="Message" MaintainState="false"
style="font: arial 11pt;" runat="server"/>
</td></tr>
</table>
</td>


</tr>

</table>
</form>
</body>
</html>
 
补充:windows2003 .net 2.0
 
后退
顶部