高手帮忙解决下gridview的问题啊,急...

jat_xf 2009-06-22 10:45:40

我在后台重新绑定 gridview 显示成这样了
http://album.hi.csdn.net/app_uploads/jat_xf/20090622/101349566.p.jpg?d=20090622101420504

在测试查询的时候能查出来数据库数据
http://album.hi.csdn.net/app_uploads/jat_xf/20090622/101356660.p.jpg?d=20090622101628019

但是运行,在页面显示的时候 却显示的没有数据
http://album.hi.csdn.net/app_uploads/jat_xf/20090622/103844301.p.jpg?d=20090622103902738

点查询打印这个页面的中数据的时候,又能显示出数据
http://album.hi.csdn.net/app_uploads/jat_xf/20090622/101357066.p.jpg?d=20090622103652629

这个是怎么回事啊?


没有重新配置数据源前
http://album.hi.csdn.net/app_uploads/jat_xf/20090622/104308332.p.jpg?d=20090622104316285
和 重新配置数据源后
http://album.hi.csdn.net/app_uploads/jat_xf/20090622/103844316.p.jpg?d=20090622104346316

gridview就只有DataKeysNames不一样
...全文
84 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
DEAN1518238610 2009-09-26
  • 打赏
  • 举报
回复
432543 25q34 b
jat_xf 2009-06-22
  • 打赏
  • 举报
回复
gridview 是直接拖的控件绑定的
LYH_OHYES 2009-06-22
  • 打赏
  • 举报
回复
gridview代碼呢?
yagebu1983 2009-06-22
  • 打赏
  • 举报
回复
单步调试一下。。。
jat_xf 2009-06-22
  • 打赏
  • 举报
回复
这个是aspx


<asp:GridView ID="GridView_product" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="GridView_product_RowDataBound" ShowFooter="True"
SkinID="gridview-width-820" OnSelectedIndexChanged="GridView_product_SelectedIndexChanged" DataSourceID="SDS_product" Height="228px" Width="761px">
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemStyle Width="30px" />
<ItemTemplate>
<asp:Label ID="Label_index" runat="server" ForeColor="Red" Text="0"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="dept_name" FooterText="合计(总):" HeaderText="所存部门" SortExpression="dept_name">
<ItemStyle Width="90px" />
</asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="product_id" DataNavigateUrlFormatString="~/corpinfo/product_detail.aspx?product_id={0}"
DataTextField="product_name" HeaderText="产品型号" Target="_blank">
<ItemStyle Width="70px" />
</asp:HyperLinkField>
<asp:BoundField DataField="color" HeaderText="色号" SortExpression="color">
<ItemStyle Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="category_name" HeaderText="类别" SortExpression="category_name">
<ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="brand_name" HeaderText="品牌" SortExpression="brand_name">
<ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="material_name" HeaderText="材质" SortExpression="material_name">
<ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="spec" HeaderText="规格" SortExpression="spec">
<ItemStyle Width="90px" />
</asp:BoundField>
<asp:BoundField DataField="unit" HeaderText="单位" SortExpression="unit">
<ItemStyle Width="30px" />
</asp:BoundField>
<asp:BoundField DataField="num" HeaderText="库存数量" SortExpression="num">
<ItemStyle Width="60px" />
</asp:BoundField>
<asp:TemplateField HeaderText="库存单价" SortExpression="price">
<ItemStyle Width="60px" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("price", "{0:C}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="memo" HeaderText="备注" SortExpression="memo">
<ItemStyle Width="90px" />
</asp:BoundField>
</Columns>
<PagerTemplate>
<table style="width: 100%">
<tr>
<td align="left" style="width: 65%">
<asp:Label ID="Label_page" runat="server" Text="共有 x 条记录 每页显示 x 条记录 共分 x 页 当前第 x 页"></asp:Label></td>
<td align="right">
<asp:LinkButton ID="LB_first" runat="server" CommandArgument="First" CommandName="Page">首页</asp:LinkButton>
<asp:LinkButton ID="LB_prev" runat="server" CommandArgument="Prev" CommandName="Page">上一页</asp:LinkButton>
<asp:LinkButton ID="LB_next" runat="server" CommandArgument="Next" CommandName="Page">下一页</asp:LinkButton>
<asp:LinkButton ID="LB_last" runat="server" CommandArgument="Last" CommandName="Page">末页</asp:LinkButton>
    转到:第
<asp:DropDownList ID="DDL_page" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_page_SelectedIndexChanged">
</asp:DropDownList>
页</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
</asp:Content>
jat_xf 2009-06-22
  • 打赏
  • 举报
回复
<asp:SqlDataSource ID="SDS_product" runat="server" ConnectionString="<%$ ConnectionStrings:newGMISConnectionString %>"
OnSelected="SDS_product_Selected" SelectCommand="sp_stock_query_product" SelectCommandType="StoredProcedure" OnSelecting="SDS_product_Selecting">
<SelectParameters>
<asp:ControlParameter ControlID="TB_model" DefaultValue="temp" Name="model" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="DDL_category" DefaultValue="0" Name="category" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="DDL_brand" DefaultValue="0" Name="brand" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="DDL_material" DefaultValue="0" Name="material" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="DDL_dept" DefaultValue="-1" Name="dept" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="TB_num_1" DefaultValue="-999999999" Name="num_1" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TB_num_2" DefaultValue="999999999" Name="num_2" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TB_spec" DefaultValue="temp" Name="spec" PropertyName="Text"
Type="String" />
<asp:Parameter Direction="InputOutput" Name="msg" Type="Int32" />
<asp:Parameter Direction="InputOutput" Name="sqlstr" Type="String" />
</SelectParameters>


<asp:HyperLink ID="HL_print" runat="server" Target="_blank">查询 打印</asp:HyperLink></td>


下面这是aspx.cs中代码
protected void Page_Load(object sender, EventArgs e)
{
Tools.AboutRight.checkPageRight("库存查询");
Page.Title = "库存管理 - 查询库存";

if (false == Tools.AboutRight.checkOptionRight("库存单价查看"))
{
GridView_product.Columns[10].Visible = false;
}

string dept_id = DDL_dept.SelectedValue;
string dept_name = DDL_dept.SelectedItem.Text;

string category_id = DDL_category.SelectedValue;
string category_name = DDL_category.SelectedItem.Text;

string brand_id = DDL_brand.SelectedValue;
string brand_name = DDL_brand.SelectedItem.Text;

string material_id = DDL_material.SelectedValue;
string material_name = DDL_material.SelectedItem.Text;

string model = TB_model.Text.Trim() == "" ? "temp" : TB_model.Text.Trim();
string num1 = TB_num_1.Text.Trim() == "" ? "-999999999" : TB_num_1.Text.Trim();
string num2 = TB_num_2.Text.Trim() == "" ? "999999999" : TB_num_2.Text.Trim();

string spec = TB_spec.Text.Trim() == "" ? "temp" : TB_spec.Text.Trim();
HL_print.NavigateUrl = "stock_print.aspx?did=" + dept_id + "&spec=" + Server.UrlEncode(spec) +
"&dname=" + Server.UrlEncode(dept_name) +
"&cid=" + category_id + "&cname=" + Server.UrlEncode(category_name) +
"&bid=" + brand_id + "&bname=" + Server.UrlEncode(brand_name) +
"&mid=" + material_id + "&mname=" + Server.UrlEncode(material_name) +
"&model=" + Server.UrlEncode(model) + "&num1=" + num1 + "&num2=" + num2;
protected void GridView_product_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label label_index = (Label)e.Row.FindControl("Label_index");
label_index.Text = Convert.ToString(GridView_product.PageIndex * GridView_product.PageSize + e.Row.RowIndex + 1);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[9].Text = numSum.ToString();
}
else if (e.Row.RowType == DataControlRowType.Pager)
{
Label label = (Label)e.Row.FindControl("Label_page");
label.Text = "共有 " + recordTotal.ToString() + "  条记录   显示 " + recordCount.ToString() + "  条记录   每页 " +
GridView_product.PageSize.ToString() + "  条记录   共分 " +
GridView_product.PageCount.ToString() + "  页   当前第 " +
Convert.ToString(GridView_product.PageIndex + 1) + "  页";

LinkButton lb_first = (LinkButton)e.Row.FindControl("LB_first");
LinkButton lb_prev = (LinkButton)e.Row.FindControl("LB_prev");
LinkButton lb_next = (LinkButton)e.Row.FindControl("LB_next");
LinkButton lb_last = (LinkButton)e.Row.FindControl("LB_last");
if (GridView_product.PageIndex == 0)
{
lb_first.Enabled = false;
lb_prev.Enabled = false;
}
else if (GridView_product.PageIndex == GridView_product.PageCount - 1)
{
lb_next.Enabled = false;
lb_last.Enabled = false;
}
DropDownList ddl = (DropDownList)e.Row.FindControl("DDL_page");
ddl.Items.Clear();
for (int i = 0; i < GridView_product.PageCount; i++)
{
ddl.Items.Add(new ListItem(Convert.ToString(i + 1), i.ToString()));
}
ddl.SelectedValue = GridView_product.PageIndex.ToString();
}
}
protected void DDL_page_SelectedIndexChanged(object sender, EventArgs e)
{
GridView_product.PageIndex = Convert.ToInt32(((DropDownList)sender).SelectedValue);
}
protected void SDS_product_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
if (e.Exception == null)
{
recordCount = e.AffectedRows;
SqlDataReader reader = null;
try
{
//Response.Write(e.Command.Parameters["@sqlstr"].Value.ToString());
reader = Tools.AboutDataSource.getDataReader(e.Command.Parameters["@sqlstr"].Value.ToString());
if (reader.Read())
{
recordTotal = Convert.ToInt32(reader[0]);
numSum = Convert.ToInt32(reader[1]);
}
}
catch (Exception ex)
{
//Response.Write(ex.Message);
}
finally
{
if (null != reader) reader.Close();
}
}

}


这个是存储过程

CREATE PROCEDURE sp_stock_query_product
(
@model nvarchar(50),
@category nvarchar(50),
@brand nvarchar(50),
@material nvarchar(50),
@dept nvarchar(50),
@num_1 nvarchar(50),
@num_2 nvarchar(50),
@spec nvarchar(50),
@msg int=0 output,
@sqlstr nvarchar(4000)='' output
)
AS
begin
declare @sql nvarchar(4000)

set @sql='select top 1000 t_stock.stock_id, p.product_name,p.model,p.code,p.factory_model,p.factory,p.category_name,p.brand_name,p.material_name,
p.color,p.spec,p.unit,t_dept.name as dept_name,t_stock.product_id,t_stock.num,t_stock.price,t_stock.sale_price, t_stock.wholesale_price,t_stock.memo
from view_product_base as p, t_stock, t_dept
where p.product_id=t_stock.product_id and t_stock.dept_id=t_dept.dept_id '

if( @model <> 'temp')
set @sql = @sql + ' and p.product_name like ''%' + @model + '%''';
if( @category <> 0)
set @sql = @sql + ' and p.category_id=' + @category + '';
if( @brand <> 0)
set @sql = @sql + ' and p.brand_id=' + @brand + '';
if( @material <> 0)
set @sql = @sql + ' and p.material_id=' + @material + '';
if( @dept <> 0)
set @sql = @sql + ' and t_stock.dept_id=' + @dept + '';
if( @num_1 >= 0)
set @sql = @sql + ' and t_stock.num>= '+ @num_1 + '';
if ( @num_2 > 0)
set @sql = @sql + ' and t_stock.num<= '+ @num_2 + '';
if( @spec<>'temp')
set @sql = @sql + ' and p.spec like ''%' + @spec + '%''';
set @sql = @sql + ' order by t_dept.name,p.product_name desc, p.product_id desc'

exec(@sql)

set @sqlstr = 'select count(p.product_id),sum(t_stock.num)
from view_product_base as p, t_stock
where p.product_id=t_stock.product_id and t_stock.dept_id=t_dept.dept_id '

if( @model <> 'temp')
set @sqlstr = @sqlstr + ' and p.product_name like ''%' + @model + '%''';
if( @category <> 0)
set @sqlstr = @sqlstr + ' and p.category_id=' + @category + '';
if( @brand <> 0)
set @sqlstr = @sqlstr + ' and p.brand_id=' + @brand + '';
if( @material <> 0)
set @sqlstr = @sqlstr + ' and p.material_id=' + @material + '';
if( @dept <> 0)
set @sqlstr = @sqlstr + ' and t_stock.dept_id=' + @dept + '';
if( @num_1 >=0)
set @sqlstr = @sqlstr + ' and t_stock.num>= '+ @num_1 + '';
if ( @num_2 >0)
set @sqlstr = @sqlstr + ' and t_stock.num<= '+ @num_2 + '';
if( @spec<>'temp')
set @sqlstr = @sqlstr + ' and p.spec like ''%' + @spec + '%''';

--print '@sqlstr='+@sqlstr

end
GO
LYH_OHYES 2009-06-22
  • 打赏
  • 举报
回复
把aspx發出來看下吧........
jat_xf 2009-06-22
  • 打赏
  • 举报
回复
gridview是直接绑定的
LYH_OHYES 2009-06-22
  • 打赏
  • 举报
回复
還是沒源碼
jat_xf 2009-06-22
  • 打赏
  • 举报
回复
第一次发帖 各位多多包涵!
jat_xf 2009-06-22
  • 打赏
  • 举报
回复
晕啊 怎么没有显示图片!修改下

我在后台重新绑定 gridview 显示成这样了


在测试查询的时候能查出来数据库数据


但是运行,在页面显示的时候 却显示的没有数据


点查询打印这个页面的中数据的时候,又能显示出数据


这个是怎么回事啊?


没有重新配置数据源前

和 重新配置数据源后


gridview就只有DataKeysNames不一样
CloneCenter 2009-06-22
  • 打赏
  • 举报
回复
代码一点都没有贴出来,让别人怎么帮你看?
LYH_OHYES 2009-06-22
  • 打赏
  • 举报
回复
貼源碼帥哥
CloneCenter 2009-06-22
  • 打赏
  • 举报
回复
我在后台重新绑定 gridview 显示成这样了
?d=20090622101420504

在测试查询的时候能查出来数据库数据
?d=20090622101628019

但是运行,在页面显示的时候 却显示的没有数据
?d=20090622103902738

点查询打印这个页面的中数据的时候,又能显示出数据
?d=20090622103652629

这个是怎么回事啊?


没有重新配置数据源前
?d=20090622104316285
和 重新配置数据源后
?d=20090622104346316

gridview就只有DataKeysNames不一样

------------------------------


楼主不会贴图?发这个图片的链接(还是文本的,不是链接)让别人怎么看?
outou 2009-06-22
  • 打赏
  • 举报
回复
帮顶

62,269

社区成员

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

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

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

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