GridView的数据绑定和显示问题 +"&bx_state="+ Server.UrlEncode(DataBinder.Eval(Container.DataItem,"bx_state").ToString())%> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 慕白兄去看看这个问题http://topic.csdn.net/u/20090731/14/cf0356e1-3908-4f75-933b-16e7ca16eeea.html?57061 查出来了 就是gridview显示不出来 要看有没有进入那两个if分支,不进入sd 是没有数据的. 我的意思是调试时,经过的每一个地方,都看看那些变量有值没有,最好用鼠标摸上去瞧瞧有时候可能是SQL语句没查询出来也有可能是条件没执行这些都不会报错,程序还是会执行完,但就容易出现不显示的情况 LZ在哪?说下地址我过去给你解决O(∩_∩)O哈哈~ 这个办法不错,还是上门服务的,哈哈...看来在csdn里面,美女的帖子还是受欢迎些 把gridview的整个html贴出来看下,顺便问一下有没有用updatepanel之类的东西。 <asp:Label ID="Label1" runat="server" Text="未关闭站点的故障信息"></asp:Label><br /> <asp:GridView ID="GridView2" runat="server" Width="101%" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GridView2_PageIndexChanging"> <Columns> <asp:TemplateField HeaderText="故障号" InsertVisible="False" SortExpression="bx_id"> <EditItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("bx_id") %>'></asp:Label> </EditItemTemplate> <ItemTemplate> <asp:Label ID="bx_id" runat="server" Text='<%# Bind("bx_id") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="区片"> <ItemTemplate> <asp:Label ID="Label6" runat="server" Text='<%# Bind("NAME") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="油站名"> <ItemTemplate> <asp:Label ID="Label7" runat="server" Text='<%# Bind("TNAME") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="油站编号" ShowHeader="False" SortExpression="bx_zdid" Visible="False"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("bx_zdid") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="bx_zdid" runat="server" Text='<%# Bind("bx_zdid") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="bx_gzfl" HeaderText="故障类别" SortExpression="bx_gzfl" /> <asp:TemplateField HeaderText="报修方式" SortExpression="bx_fs"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("bx_fs") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("bx_fs") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="报修日期时间" SortExpression="bx_date"> <ItemTemplate> <asp:Label ID="bx_date" runat="server" Text='<%# Bind("bx_date") %>'></asp:Label> <asp:Label ID="bx_hour" runat="server" Text='<%# Bind("bx_hour") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="故障状态" SortExpression="bx_state"> <EditItemTemplate> <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("bx_state") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="bx_state" runat="server" Text='<%# Bind("bx_state") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="查看明细"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"DetailsStationProblems.aspx?bx_id=" + DataBinder.Eval(Container.DataItem,"bx_id")+"&bx_state="+ Server.UrlEncode(DataBinder.Eval(Container.DataItem,"bx_state").ToString())%> '>查看</asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle Font-Size="Small" HorizontalAlign="Center" BackColor="#E3EAEB" /> <SelectedRowStyle BackColor="#C5BBAF" BorderColor="#C0C0FF" Font-Bold="True" ForeColor="#333333" /> <PagerStyle HorizontalAlign="Center" BackColor="#666666" ForeColor="White" /> <PagerTemplate> <table> <tr> <td> <asp:Label ID="LabelCurrentPage" runat="server" Font-Size="Small">当前页:<%# ((GridView)Container.NamingContainer).PageIndex + 1 %></asp:Label></td> <td> <asp:Label ID="LabelPageCount" runat="server" Font-Size="Small">总页数:<%# ((GridView)Container.NamingContainer).PageCount %></asp:Label></td> <td> <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Font-Size="Small" ForeColor="white">首页</asp:LinkButton></td> <td> <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Font-Size="Small" ForeColor="white">上一页</asp:LinkButton></td> <td> <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>" Font-Size="Small" ForeColor="white">下一页</asp:LinkButton></td> <td> <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>" Font-Size="Small" ForeColor="white">尾页</asp:LinkButton></td> </tr> </table> </PagerTemplate> <AlternatingRowStyle BackColor="White" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" Font-Size="Small" ForeColor="White" /> <EditRowStyle BackColor="#7C6F57" /> </asp:GridView>这是能用到的一部分 如果传过来的值是,"已提报" 。错误可能在这两行GridView1.DataSource = sd.CurrentDS; GridView1.DataBind(); sd.CurrentDS 这个应该是个方法吧。先给一个好使的SQL语句查询一下“select * from ...”在使用sd.CurrentDS方法 将查询后的结果赋给GridView1.DataSource。看看能不能显示出来。 gridview绑定的字段名貌似和sql语句中的字段名不一样啊 调试的时候,执行完这两行看一下 GridView1.Rows.Count是否大于0,如果==0那么就是没有绑到。 你的GridView1绑定的是数据库里的字段,你查询的时候已经as成中文了,数据肯定是绑定不上的 走断点 把SQL语句复制下来,在数据库中执行 看看什么效果~~~~~~~~~~~~ 这个是页面1的前台页面 SQl语句是页面2的页面2的前台没绑定,后台要显示的字段是不一样的呀 先使用一个简单的sql语句 ,将查询后的结果 绑定到gridview中,看看gridview什么效果~~~~~~ 看看第二个页面的GridView1的HTML 第二个呀 什么也没绑哈<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="DetailsStationProblems.aspx.cs" Inherits="ywkh_DetailsStationProblems" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True"> <RowStyle Font-Size="Small" HorizontalAlign="Center" BackColor="#E3EAEB" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" Font-Size="Small" ForeColor="White" /> <SelectedRowStyle BackColor="#C5BBAF" BorderColor="#C0C0FF" Font-Bold="True" ForeColor="#333333" /> <PagerStyle HorizontalAlign="Center" BackColor="#666666" ForeColor="White" /> <PagerTemplate> <table> <tr> <td> <asp:Label ID="LabelCurrentPage" runat="server" Font-Size="Small">当前页:<%# ((GridView)Container.NamingContainer).PageIndex + 1 %></asp:Label></td> <td> <asp:Label ID="LabelPageCount" runat="server" Font-Size="Small">总页数:<%# ((GridView)Container.NamingContainer).PageCount %></asp:Label></td> <td> <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Font-Size="Small" ForeColor="white">首页</asp:LinkButton></td> <td> <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Font-Size="Small" ForeColor="white">上一页</asp:LinkButton></td> <td> <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>" Font-Size="Small" ForeColor="white">下一页</asp:LinkButton></td> <td> <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>" Font-Size="Small" ForeColor="white">尾页</asp:LinkButton></td> </tr> </table> </PagerTemplate> </asp:GridView></asp:Content> 这就奇怪了.sd.CurrentDS; 看看他他的Tables.CountTables[1].Rows.Count 在结果集上设断点,看有没有数据还有,你要先设好需要绑定的项,估计你数据取出来了,但是要在gridview上提供数据绑定的地方 比如绑定到控件或像这样 <asp:BoundField DataField="id" HeaderText="ID"></asp:BoundField> 还没解决呐?把Gridview的AutoGenerateColumns = "true" Gridview的AutoGenerateColumns = "true" 这个加了出来有什么用,只是出来一些空白,别人要数据 哇终于在CSDN见到女的啦而且是美女哦 设计一个ASP.NET页面(C#) 请教有关gridview控件问题 怎样用javascript读取指定页面的源文件 asp.net 按输入内容进行模糊查询 我有个服务器,装上了SQL,为什么连接不了其它的SQL 用什么加密比较好和比较安全??? 关于treeview的动态绑定 如何让Iframe根据页面内容自动调整大小而不出现滚动条呢? 新人,100分,求救关于AJAX.NET的Tabpanel的问题 小弟问个问题,网上下了一个网站如何打开并运行 linq to xml 转换类型问题 asp.net中调用Bll层的方法
http://topic.csdn.net/u/20090731/14/cf0356e1-3908-4f75-933b-16e7ca16eeea.html?57061
有时候可能是SQL语句没查询出来
也有可能是条件没执行
这些都不会报错,程序还是会执行完,但就容易出现不显示的情况
看来在csdn里面,美女的帖子还是受欢迎些
把gridview的整个html贴出来看下,顺便问一下有没有用updatepanel之类的东西。
<asp:GridView ID="GridView2" runat="server" Width="101%" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GridView2_PageIndexChanging">
<Columns>
<asp:TemplateField HeaderText="故障号" InsertVisible="False" SortExpression="bx_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("bx_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="bx_id" runat="server" Text='<%# Bind("bx_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="区片">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="油站名">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("TNAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="油站编号" ShowHeader="False" SortExpression="bx_zdid" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("bx_zdid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="bx_zdid" runat="server" Text='<%# Bind("bx_zdid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bx_gzfl" HeaderText="故障类别" SortExpression="bx_gzfl" />
<asp:TemplateField HeaderText="报修方式" SortExpression="bx_fs">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("bx_fs") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("bx_fs") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="报修日期时间" SortExpression="bx_date"> <ItemTemplate>
<asp:Label ID="bx_date" runat="server" Text='<%# Bind("bx_date") %>'></asp:Label>
<asp:Label ID="bx_hour" runat="server" Text='<%# Bind("bx_hour") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="故障状态" SortExpression="bx_state">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("bx_state") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="bx_state" runat="server" Text='<%# Bind("bx_state") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="查看明细">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"DetailsStationProblems.aspx?bx_id=" + DataBinder.Eval(Container.DataItem,"bx_id")+"&bx_state="+ Server.UrlEncode(DataBinder.Eval(Container.DataItem,"bx_state").ToString())%> '>查看</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle Font-Size="Small" HorizontalAlign="Center" BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" BorderColor="#C0C0FF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle HorizontalAlign="Center" BackColor="#666666" ForeColor="White" />
<PagerTemplate>
<table>
<tr>
<td>
<asp:Label ID="LabelCurrentPage" runat="server" Font-Size="Small">当前页:<%# ((GridView)Container.NamingContainer).PageIndex + 1 %></asp:Label></td>
<td>
<asp:Label ID="LabelPageCount" runat="server" Font-Size="Small">总页数:<%# ((GridView)Container.NamingContainer).PageCount %></asp:Label></td>
<td>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Font-Size="Small" ForeColor="white">首页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"
Font-Size="Small" ForeColor="white">上一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"
Font-Size="Small" ForeColor="white">下一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"
Font-Size="Small" ForeColor="white">尾页</asp:LinkButton></td>
</tr>
</table>
</PagerTemplate>
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" Font-Size="Small" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
</asp:GridView>这是能用到的一部分
GridView1.DataSource = sd.CurrentDS;
GridView1.DataBind(); sd.CurrentDS 这个应该是个方法吧。先给一个好使的SQL语句查询一下“select * from ...”在使用sd.CurrentDS方法 将查询后的结果赋给GridView1.DataSource。看看能不能显示出来。
SQl语句是页面2的
页面2的前台没绑定,后台要显示的字段是不一样的呀
GridView1
的HTML
什么也没绑哈
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="DetailsStationProblems.aspx.cs" Inherits="ywkh_DetailsStationProblems" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True">
<RowStyle Font-Size="Small" HorizontalAlign="Center" BackColor="#E3EAEB" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" Font-Size="Small" ForeColor="White" />
<SelectedRowStyle BackColor="#C5BBAF" BorderColor="#C0C0FF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle HorizontalAlign="Center" BackColor="#666666" ForeColor="White" />
<PagerTemplate>
<table>
<tr>
<td>
<asp:Label ID="LabelCurrentPage" runat="server" Font-Size="Small">当前页:<%# ((GridView)Container.NamingContainer).PageIndex + 1 %></asp:Label></td>
<td>
<asp:Label ID="LabelPageCount" runat="server" Font-Size="Small">总页数:<%# ((GridView)Container.NamingContainer).PageCount %></asp:Label></td>
<td>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Font-Size="Small" ForeColor="white">首页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page" Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"
Font-Size="Small" ForeColor="white">上一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"
Font-Size="Small" ForeColor="white">下一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"
Font-Size="Small" ForeColor="white">尾页</asp:LinkButton></td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
</asp:Content>
看看他
他的Tables.Count
Tables[1].Rows.Count
还有,你要先设好需要绑定的项,估计你数据取出来了,但是要在gridview上提供数据绑定的地方 比如绑定到控件或像这样 <asp:BoundField DataField="id" HeaderText="ID"></asp:BoundField>
终于在CSDN见到女的啦而且是美女哦