怎么绑定到gridview上

xuexiziji 2008-07-22 11:02:47
环境.net2008,有这样几个表
学生表 学号,姓名 ....
1 张 ...
2 里 ...
......

课程表 课程号 课程名
1 语文
2 数学
3 计算机
.........
成绩表 学号,课程号 成绩类型号
1 1 a
1 2 b
1 3 c
2 1 b
2 2 c
2 3 c
........
成绩类型表 成绩类型号 成绩
a 优秀
b 良好
c 好
d 差
........
通过这几个表得到一个这样的结果
学号 姓名 语文 数学 计算机
1 张 优秀 良好 好
2 里 良好 好 好


然后绑定到gridview上面,并且用学生姓名 做个连接,通过传递 学生号 去别的页面。比如b.aspx
请尽量 把代码粘贴出来。谢谢。
一定高分酬谢。

...全文
335 34 打赏 收藏 转发到动态 举报
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
janelee1029 2008-07-23
  • 打赏
  • 举报
回复
借lz地盘广告一下~~~


有人对微软的SDE或者SDET感兴趣吗?


我是HR,招赴MS的vender,工作地点北京,要求如下:


1.solid c#/c++ coding experience at least 2 years

2.good english communication skill both on written and spoken

3.smart and fast learning skills



有感兴趣或您有认识的朋友请和我联系:-) 我是小李。

邮箱:independencity@sina.com

MSN: independencity@live.cn

QQ: 597674362
billlyh 2008-07-23
  • 打赏
  • 举报
回复
ding!!!!!!!!!!!!!
yuantaolzu 2008-07-23
  • 打赏
  • 举报
回复
mark
xuexiziji 2008-07-23
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 wen_ye 的回复:]
我做了一种 不是绑定的
前台代码
<div id="reslut" style="font-size:14px; font-weight:bold;"> <%=Str%> </div>

后台代码
public string Str = "";

public void Show(){
DataTable dt = SelectReslut("select * from course");
DataTable dtcount = SelectReslut("select * from stuInfo");

string temp = "";
temp+=" <table> <tr>";
temp += "…
[/Quote]
非常感谢。这个动态增加列,能够对应 课程变化的情况,不过有两个问题,
学生名 做个连捷列,并且传递 学生号,怎么办
还有一个,你这个是不是只能在 网页启动的时候用,如果改变条件,可不可以调用呢。
xuexiziji 2008-07-23
  • 打赏
  • 举报
回复
[Quote=引用 28 楼 JeffChung 的回复:]
引用 26 楼 yagebu1983 的回复:
wzy_love_sly 回答的很完美!!!


wzy_love_sly有心,呵呵
[/Quote]
我也非常感谢 wzy_love_sly,只是现在还有一个小问题。
按照 他说的绑定后,gridview是不能自动增加列的,如果课程表里,添加了一个课程,
这个时候不能对应亚。
jinlong5200 2008-07-22
  • 打赏
  • 举报
回复
用数据库中的试图来拖拽下就可以了,简单
yilanwuyu123 2008-07-22
  • 打赏
  • 举报
回复
mark
xuexiziji 2008-07-22
  • 打赏
  • 举报
回复
怎么绑定呢,用sqldatasource绑定吗。还是用datatable
用datatable绑定后,学生名的连接列,怎么弄。
视图不能使用。
zhouchenguang 2008-07-22
  • 打赏
  • 举报
回复
做一个联合查询
xqy_2007 2008-07-22
  • 打赏
  • 举报
回复
写一个存储过程将你需要的内容连起来,然后将这个存储过程作为DataSet的数据源,
最后再将得到的DataSet作为gridview的数据源就可以搞定.
journeydj 2008-07-22
  • 打赏
  • 举报
回复
语句不复杂
成绩表作为主表。leftjoin其他三个表就可以了。三列code取三列名字。
SELECT 需要的列
FROM 成绩表
LEFT JOIN 学生表 ON 学生表.学号=成绩表.学号
LEFT JOIN 课程表 ON 课程表.课程号=成绩表.课程号
LEFT JOIN 成绩类型表 ON 成绩类型表 .成绩类型号 =成绩表.成绩类型号
WHERE 针对成绩表的条件 order by 排序列
falx2004 2008-07-22
  • 打赏
  • 举报
回复
left join 关联查询
jryu2k5 2008-07-22
  • 打赏
  • 举报
回复
有点笨的方法:在数据库中创建一个视图,再使用学号=?进行查询
fellowcheng 2008-07-22
  • 打赏
  • 举报
回复
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="13" Width="99%" DataKeyNames="BriefingID" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True" OnSorting="GridView1_Sorting" EmptyDataText="没有任何数据">
<Columns>
<asp:BoundField DataField="BriefingID" Visible="False"/>
<asp:BoundField DataField="UserName" HeaderText="发布者" SortExpression="UserName" Visible="False">
<ItemStyle HorizontalAlign="Center" Wrap="False"/>
</asp:BoundField>
<asp:TemplateField HeaderText="标    题" SortExpression="Title">
<ItemTemplate>
  <a style='color:Blue;display:<%# (Eval("State").ToString()=="1" && Eval("RecState").ToString()=="0")?" ":"none" %>' href='BriefingDetail.aspx?id=<%# Eval("BriefingID") %>' ><%# Eval("Title").ToString().Length > 20 ? Eval("Title").ToString().Substring(0,20) + "..." : Eval("Title").ToString() %><img border="0" src="../../images/newAlert.GIF" /></a>
<a style='display:<%# (Eval("State").ToString()!="1" || Eval("RecState").ToString()!="0")?" ":"none" %>' href='BriefingDetail.aspx?id=<%# Eval("BriefingID") %>' ><%# Eval("Title").ToString().Length > 20 ? Eval("Title").ToString().Substring(0,20) + "..." : Eval("Title").ToString() %></a>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="类型" SortExpression="ClassifyID">
<ItemStyle HorizontalAlign="Center" Wrap="False"/>
<ItemTemplate>
<span><%# GetClassifyName(Eval("ClassifyID").ToString())%></span>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SendDate" HeaderText="发布日期" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="False" SortExpression="SendDate desc">
<ItemStyle HorizontalAlign="Center" Width="100px" Wrap="False"/>
</asp:BoundField>
<asp:TemplateField Visible="False">
<ItemTemplate>
<a style=display:<%# Eval("State").ToString()=="0"?" ":"none" %> href=<%# "BriefingManage.aspx?Operation=Edit&id="+Eval("BriefingID") %> >修改</a>  
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False"/>
</asp:TemplateField>
<asp:TemplateField></asp:TemplateField>

</Columns>
<pagertemplate>
<table width="100%">
<tr>
<td style="text-align:right">
每页<%# ((GridView)Container.Parent.Parent).PageSize %>条
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />/<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" Enabled='<%# ((GridView)Container.Parent.Parent).PageIndex != 0 %>' causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex != 0 %>" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex+1 != ((GridView)Container.Parent.Parent).PageCount %>" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex+1 != ((GridView)Container.Parent.Parent).PageCount %>" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
转到<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />
</td>
</tr>
</table>
</pagertemplate>
</asp:GridView>
blue_summer 2008-07-22
  • 打赏
  • 举报
回复
SQL语句很复杂啊,上数据库版找牛人帮你搞定。。。
剩下好做,显示的学生名套一个<A href='b.aspx?&id=<%# Eval("学生号") %>'><%# Eval("学生名") %></A>
amandag 2008-07-22
  • 打赏
  • 举报
回复
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="true" >
<Columns>
<asp:BoundField DataField="学号" SortExpression="学号" />
<asp:BoundField DataField="姓名" />
<asp:BoundField DataField="语文" />
<asp:BoundField DataField="数学" />
<asp:BoundField DataField="计算机" />
</Columns>
</asp:GridView>

GridView1.DataSource = RunProcedure("存储过程名",参数).tables[0];
GridView1.DataBind();
JeffChung 2008-07-22
  • 打赏
  • 举报
回复
[Quote=引用 26 楼 yagebu1983 的回复:]
wzy_love_sly 回答的很完美!!!
[/Quote]

wzy_love_sly有心,呵呵
wen_ye 2008-07-22
  • 打赏
  • 举报
回复
我做了一种 不是绑定的
前台代码
<div id="reslut" style="font-size:14px; font-weight:bold;"><%=Str%></div>

后台代码
public string Str = "";

public void Show(){
DataTable dt = SelectReslut("select * from course");
DataTable dtcount = SelectReslut("select * from stuInfo");

string temp = "";
temp+="<table><tr>";
temp += "<td>学号</td>";
temp += "<td>姓名</td>";
for (int i = 0; i < dt.Rows.Count;i++ )
{
temp += "<td>"+dt.Rows[i]["cou_Name"]+"</td>";
}
temp+="</tr>";
for (int j = 0; j < dtcount.Rows.Count;j++ )
{
temp += "<tr>";
temp += "<td>"+dtcount.Rows[j]["stu_Id"]+"</td>";
temp += "<td>" + dtcount.Rows[j]["stu_Name"] + "</td>";
DataTable dtreslut = SelectReslut("select s.stu_Id,s.stu_Name,c.cou_Name,t.type_Name from stuInfo s,course c,grade_type t,grade g where s.stu_Id=g.stu_Id and c.cou_Id=g.cou_Id and t.type_Id=g.type_Id and s.stu_Id=" + dtcount.Rows[j]["stu_Id"] + "");
for (int z = 0; z < dtreslut.Rows.Count;z++ )
{
temp += "<td>" + dtreslut.Rows[z]["type_Name"] + "</td>";
}
temp += "</tr>";
}
temp += "</table>";
Str=temp;
}

private DataTable SelectReslut(string sql)
{
SqlConnection con = new SqlConnection("Data Source=.;uid=test;pwd=123321;database=master;");

SqlDataAdapter da = new SqlDataAdapter(sql,con);

DataSet ds = new DataSet();
da.Fill(ds,"reslut");
DataTable dt = ds.Tables[0];
return dt;
}
yagebu1983 2008-07-22
  • 打赏
  • 举报
回复
wzy_love_sly 回答的很完美!!!
xuexiziji 2008-07-22
  • 打赏
  • 举报
回复
????????
加载更多回复(14)

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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