大家来看看我的代码有什么问题

楚凌风 2007-12-05 05:20:56
一个页面中有一个dropdownlist ddlDepartment和一个gridview GridviewAuditZB,我要通过ddlDepartment得到depId,再通过Gridview显示该depId对应的纪录,出现的问题是GridView没有显示,DEBUG调试又查不出错

public partial class AuditReportPage : System.Web.UI.Page
{
PRO_ZB _zb = null;//
PRO_DEPARTMENT _depart = null;//
/// <summary>
/// Page_load事件,调用绑定ddlDepartment方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDdlDepartment();
}
}
/// <summary>
/// 绑定ddlDepartment方法
/// </summary>
protected void BindDdlDepartment()
{
_depart = new PRO_DEPARTMENT();
ddlDepartment.DataSource = _depart.GetAllDepartInfo().Tables[0].DefaultView;
ddlDepartment.DataTextField = "DEPARTMENT";
ddlDepartment.DataValueField = "DEPARTMENT";
ddlDepartment.DataBind();
}
/// <summary>
/// 绑定GridviewAuditZB方法
/// </summary>
/// <param name="depId"></param>
protected void BindGrid(long depId)
{
_zb = new PRO_ZB();
DataSet ds = _zb.GetZBByWeekStaAndDepId(0, depId);
if (ds.Tables[0].Rows.Count==0)
{
DataRow row = ds.Tables[0].NewRow();
row["ZBID"] = 0;
ds.Tables[0].Rows.Add(row);
}
GridViewAuditZB.DataSource = ds.Tables[0].DefaultView;
GridViewAuditZB.DataBind();
}


/// <summary>
/// ddlDepartment的selectIndexChanged事件,调用绑定GridviewAuditZB方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
_depart = new PRO_DEPARTMENT();
string depname = ddlDepartment.SelectedValue;
long depId = _depart.GetIdByName(depname);
if(depId>0)
{
BindGrid(depId);
}
}
}

页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DepartAuditReportPage.aspx.cs" Inherits="AuditReportPage" %>

<!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 runat="server">
<title>无标题页</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body topmargin="35px">
<form id="form1" runat="server">
<div class="main">
<table style="width: 760px; height: 1px" id="mainTable">
<tr>
<td align="center" colspan="3" style="height: 36px; width: 100%; background-color: #507cd1;">
<strong><span style="font-size: 16pt; color: #ffffff;">          
报表审核</span></strong></td>
</tr>
<tr>
<td align="right" colspan="3" rowspan="1" style="width: 100%; height: 19px" valign="top">
<asp:DropDownList ID="ddlDepartment" runat="server" OnSelectedIndexChanged="ddlDepartment_SelectedIndexChanged">
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="3" style="height: 184px; width: 100%;" rowspan="1" valign="top" align="right">
 <asp:GridView ID="GridViewAuditZB" runat="server" AutoGenerateColumns="False" Height="100%" Width="100%" CellPadding="1" ForeColor="#333333" GridLines="None" BackColor="#E0E0E0" BorderWidth="1px" CaptionAlign="Right" CellSpacing="1" PageSize="25">
<Columns>
<asp:TemplateField HeaderText="报表编号">
<ItemTemplate>
  
<asp:HyperLink ID="linkZBID" runat="server" NavigateUrl='<%# "~/AuditWeeklyReportDetail.aspx?zbId="+DataBinder.Eval(Container, "DataItem.ZBID") %>'
Text='<%# Eval("ZBID") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="汇报人">
<ItemTemplate>
<%#Eval("USERNAME")%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="15%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="汇报时间(周)">
<ItemTemplate>
<%#Eval("WEEKNUM")%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="15%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="工作开始时间">
<ItemTemplate>
<%#Eval("WEEKSTART")%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="30%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="工作结束时间">
<ItemTemplate>
<%#Eval("WEEKEND")%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="30%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#EFF3FB" BorderColor="#E0E0E0" BorderStyle="None" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</td>
</tr>
</table>

</div>
</form>
</body>
</html>
...全文
66 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2007-12-05
  • 打赏
  • 举报
回复
设置dropdownlist ddlDepartment中的autopostback="true",这样才能自动将数据返回服务器
楚凌风 2007-12-05
  • 打赏
  • 举报
回复
LS的来晚了,呵呵
lazyfish 2007-12-05
  • 打赏
  • 举报
回复
没有设置autopostback
symbol441 2007-12-05
  • 打赏
  • 举报
回复
断点调试,应该ds.Tables[0].Rows.Count==0这句是成立的.所以才没有数据

if (ds.Tables[0].Rows.Count==0)
{
DataRow row = ds.Tables[0].NewRow();
row["ZBID"] = 0;
ds.Tables[0].Rows.Add(row);

}
楚凌风 2007-12-05
  • 打赏
  • 举报
回复
哦,该死该死,居然忘了设autopostback,谢谢hy_lihuan
whzh719 2007-12-05
  • 打赏
  • 举报
回复
没看明白
hy_lihuan 2007-12-05
  • 打赏
  • 举报
回复
<asp:DropDownList ID="ddlDepartment" runat="server" OnSelectedIndexChanged="ddlDepartment_SelectedIndexChanged">
</asp:DropDownList>

少设置一个属性autopostback
honey52570 2007-12-05
  • 打赏
  • 举报
回复
接分

眼花
tantaiyizu 2007-12-05
  • 打赏
  • 举报
回复

到底有什么问题呢?

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧