我用datagrid,dataset也有数据了,调试(databind和datasource)通过,但是就是页面不现实datagrid,有什么可能让如此情况发生?

wind2004 2005-05-04 04:27:22
一个问题:
我用datagrid,dataset也有数据了,调试(databind和datasource)通过,但是就是页面不现实datagrid,有什么可能让如此情况发生?
...全文
240 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
njqibin 2005-06-24
  • 打赏
  • 举报
回复
数据库里没数据,找一些数据放进去就可以了。
pbooter 2005-06-17
  • 打赏
  • 举报
回复
AutoGenerateColumns="True"
beijingbeerman 2005-06-17
  • 打赏
  • 举报
回复
DataGrid1.DataSource=myDataset.Tables["selstudent"].defaultView();
DataGrid1.DataBind();
stevenhzj 2005-05-04
  • 打赏
  • 举报
回复
显式的写一次DataGrid1.Visible=true;
wind2004 2005-05-04
  • 打赏
  • 举报
回复


*****************************************************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using InfoPlat.Components;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Configuration;

namespace InfoPlat.AddAbsence {

public class AddAbsence : System.Web.UI.Page {
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.Label Title;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label L_tname;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList D_tCourse;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.DropDownList D_tCoursetime;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.DropDownList D_tWeek;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.DropDownList D_tTerm;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private static SqlConnection myConnection = null;


public AddAbsence()
{
Page.Init += new System.EventHandler(Page_Init);
}

private void Page_Load(object sender, System.EventArgs e)
{
L_tname.Text = Request.Cookies["InfoPlat_UserNo"].Value;
String command = "select chname from course,opencourse where course.id=opencourse.courseid and opencourse.teachername = "+"'"+L_tname.Text+"'";
DataSet myDataset = pubsql.sql(command);
for(int i = 0 ;i<myDataset.Tables[0].Rows.Count;i++)
{
D_tCourse.Items.Add(myDataset.Tables[0].Rows[i].ItemArray.GetValue(0).ToString());
}
///////////////////////////////////////////////
command = "select classtime from opencourse where teachername = "+"'"+L_tname.Text+"'"+" and opencourse.courseid = (select id from course where course.chname = "+"'"+D_tCourse.SelectedItem.Text+"'"+")";
myDataset.Reset();
myDataset = pubsql.sql(command);
for (int i= 0 ;i<myDataset.Tables[0].Rows.Count;i++)
{
string [] split=myDataset.Tables[0].Rows[i].ItemArray.GetValue(0).ToString().Split(new Char [] {' '});
for(int j= 0; j<split.Length;j++)
{
D_tCoursetime.Items.Add(split[j]);
}
}
////////////////////////////////////////
command = "select term from opencourse,course where opencourse.teachername = "+"'"+L_tname.Text+"'"+" and course.id=opencourse.courseid and course.chname = "+"'"+D_tCourse.SelectedItem.Text+"'";
myDataset.Reset();
myDataset = pubsql.sql(command);
for (int i= 0 ;i<myDataset.Tables[0].Rows.Count;i++)
{
string [] split=myDataset.Tables[0].Rows[i].ItemArray.GetValue(0).ToString().Split(new Char [] {' '});
for(int j= 0; j<split.Length;j++)
{
D_tTerm.Items.Add(split[j]);
}
}
/////////////////////////////////////////
command = "select stuno as '学号',student.chname as '姓名',sex as '性别',student.grade as '年级' from student,stuselcourse,opencourse,course where stuselcourse.stuid=student.id and stuselcourse.opencourseid=opencourse.id and opencourse.teachername = "+"'"+L_tname.Text+"'"+" and course.chname="+"'"+D_tCourse.SelectedItem.Text+"'"+" and opencourse.term="+"'"+D_tTerm.SelectedItem.Text+"'"+" and course.id=opencourse.courseid order by student.stuno";
myDataset.Reset();
try
{
myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand sqlcommand = new SqlCommand(command,myConnection);
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlcommand);
sqlAdapter.Fill(myDataset,"selstudent");
DataGrid1.DataSource=myDataset.Tables["selstudent"];
DataGrid1.DataBind();


}
catch
{
Console.Write("asdasd");
}
}

private void Page_Init(object sender, EventArgs e) {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
}

#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.D_tWeek.SelectedIndexChanged += new System.EventHandler(this.D_tWeek_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void D_tWeek_SelectedIndexChanged(object sender, System.EventArgs e)
{

}



}
}
wind2004 2005-05-04
  • 打赏
  • 举报
回复
<%@ Register TagPrefix="INFOPLAT" TagName="Header" Src="../Controls/_Header.ascx" %>
<%@ Register TagPrefix="INFOPLAT" TagName="Menu" Src="../Controls/_Menu.ascx" %>
<%@ Page Language="c#" CodeBehind="AddAbsence.aspx.cs" AutoEventWireup="false" Inherits="InfoPlat.AddAbsence.AddAbsence" %>
<HTML>
<HEAD>
<title>员工详细资料</title>
<LINK href="../Style.css" type="text/css" rel="stylesheet">
<script language="javascript" src="../script.js"></script>
</HEAD>
<body bottomMargin="0" leftMargin="0" background="../images/sitebkgrd.gif" topMargin="0"
rightMargin="0" marginheight="0" marginwidth="0">
<form id="Form1" runat="server" method="post">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td colSpan="2"><INFOPLAT:HEADER id="Header1" runat="server"></INFOPLAT:HEADER></td>
</tr>
<tr>
<td vAlign="top"><INFOPLAT:MENU id="Menu1" runat="server"></INFOPLAT:MENU><IMG height="1" src="../images/1x1.gif" width="145">
</td>
<td vAlign="top" noWrap align="left" width="100%">
<table height="100%" cellSpacing="0" cellPadding="0" width="100%" align="left" border="0">
<tr vAlign="top">
<td noWrap><br>
<IMG height="1" src="../images/1x1.gif" width="24" align="left">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td class="ContentHead"><IMG height="32" src="../images/1x1.gif" width="60" align="left"> 
<asp:label id="Title" runat="server">添加缺勤人员</asp:label><br>
</td>
</tr>
</table>
<IMG height="1" src="../images/1x1.gif" width="92" align="left">
<table height="100%" cellSpacing="0" cellPadding="0" border="0">
<tr vAlign="top">
<td>
<br>
 
<br>
 
<br>
<br>
<asp:imagebutton id="ImageButton1" runat="server" ImageUrl="../images/submit.gif"></asp:imagebutton></td>
<P><FONT face="宋体"></FONT><FONT face="宋体"></FONT>
<P> 
<asp:Label id="Label1" runat="server" Width="40px">欢迎</asp:Label>
<asp:Label id="L_tname" runat="server">Label</asp:Label><FONT face="宋体"> 
<asp:Label id="Label6" runat="server">老师</asp:Label><FONT face="Times New Roman">   
</FONT>
<asp:Label id="Label2" runat="server">以下是您的课程</asp:Label>
<asp:DropDownList id="D_tCourse" runat="server"></asp:DropDownList></FONT><FONT face="Times New Roman">     
<asp:Label id="Label3" runat="server">课程时间</asp:Label>
<asp:DropDownList id="D_tCoursetime" runat="server"></asp:DropDownList>  
<asp:Label id="Label7" runat="server">学期数:</asp:Label> 
<asp:DropDownList id="D_tTerm" runat="server"></asp:DropDownList>
<asp:Label id="Label4" runat="server">第</asp:Label> 
<asp:DropDownList id="D_tWeek" runat="server" Width="44px">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:Label id="Label5" runat="server">周</asp:Label></FONT>
<P></P>
<P><FONT face="宋体;</FONT></P>
<P><FONT face="宋体"></FONT> </P>
<P><FONT face="宋体"></FONT> </P>
<P><FONT face="宋体"></FONT> </P>
<P><FONT face="宋体">              
<asp:DataGrid id="DataGrid1" runat="server" Width="480px" SelectedIndex="0" ForeColor="White"
BackColor="#C0C000" BorderColor="#C0C0FF" HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<HeaderStyle HorizontalAlign="Center" BorderStyle="Solid" BorderColor="White" BackColor="Blue"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="选择">
<ItemTemplate>
<input type="hidden" id="SelectedID" runat="server"
value='<%# Container.ItemIndex%>' NAME="SelectedID"/>
<asp:CheckBox ID="chkExport" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid></P>
                                   </FONT></P>
<P><FONT face="宋体"></FONT> </P>
<P><FONT face="宋体"></FONT><FONT face="宋体"></FONT>
<br>
</P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
</P>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</HTML>










hackate 2005-05-04
  • 打赏
  • 举报
回复
还是把全码都铁了哈
LoveCherry 2005-05-04
  • 打赏
  • 举报
回复
Console.Write("asdasd");
????????????
LoveCherry 2005-05-04
  • 打赏
  • 举报
回复
sql语句呢?DataSource可以直接设置成DataSet,没有设置AutoGenerateColumns="False"的情况下也可以不绑定列
hchxxzx 2005-05-04
  • 打赏
  • 举报
回复
不绑定列,也是可以显示的,因为有个"自动生成列"的属性,不进行任何设置即可(默认为自动生成列)
如果楼主绑定列后仍然显示不了,那怀疑是你的数据表是空表.
datasource不能直接和dataset绑定,必须和dataset里面的某个表绑定者可以.
只要有指定datasource及databind即可.
this.datagrid1.DataSource = 数据源
this.datagrid1.DataBind();
wind2004 2005-05-04
  • 打赏
  • 举报
回复
还有,要是我已经有了dataset,是不是直接datasource和databind一下就可以了?

还有以前做的时候我没绑定过列也照样能用压
hackate 2005-05-04
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3896/3896149.xml?temp=.5798761

参考这里的datagrid使用方法。。

比如你有4列,然后对应要在前台.aspx写下

<asp:DataGrid id="DataGrid1" runat="server" Width="276px" Height="100px" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="id" HeaderText="编号"></asp:BoundColumn>
<asp:BoundColumn DataField="yuwen" HeaderText="语文"></asp:BoundColumn>
<asp:BoundColumn DataField="shuxue" HeaderText="数学"></asp:BoundColumn>
<asp:BoundColumn DataField="yingyu" HeaderText="英语"></asp:BoundColumn>
</Columns>
</asp:DataGrid>

DataField是你数据库里的字段,。。。
hackate 2005-05-04
  • 打赏
  • 举报
回复
所以说嘛,你没拌定列。不行嘛。。
wind2004 2005-05-04
  • 打赏
  • 举报
回复
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
hackate 2005-05-04
  • 打赏
  • 举报
回复
以上代码没有问题,那你的.aspx代码呢?发来看看捏
wind2004 2005-05-04
  • 打赏
  • 举报
回复
try
{
myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand sqlcommand = new SqlCommand(command,myConnection);
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlcommand);
sqlAdapter.Fill(myDataset,"selstudent");
DataGrid1.DataSource=myDataset.Tables["selstudent"];
DataGrid1.DataBind();


}
catch

{
Console.Write("asdasd");
}

command 是一句sql语句,验证过是正确地
以上单布都通过
请大师门帮帮我
hackate 2005-05-04
  • 打赏
  • 举报
回复
对,帖出代码吧,估计很可能是没制订列吧
LoveCherry 2005-05-04
  • 打赏
  • 举报
回复
贴出代码吧
TrojanSckiss 2005-05-04
  • 打赏
  • 举报
回复
1.没有调用DataBind()函数.
2.你要显示的是中文数据,而在web.Config里的处理你用的是UTF-8改成gb2312.
zhangaipl 2005-05-04
  • 打赏
  • 举报
回复
代码贴出来看看.
加载更多回复(1)

62,266

社区成员

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

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

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

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