最近做一个项目,用到页面传值,代码出来以后,运行出了问题,提示:字符串格式不正确,请问各位大大原因,谢谢了!代码如下:html:
<asp:DataList ID="DataList1" runat="server" Height="222px"
RepeatDirection="Horizontal" Width="756px" RepeatColumns="5" >
<ItemTemplate>
<a href="/Model/Product/ProductDetail.aspx?id=productID">
<img src='<%# DataBinder.Eval(Container.DataItem, "pic")%>' />
</a>
</ItemTemplate>
</asp:DataList>
这是用datalist绑定图片,然后他图片有个链接,然后传值过去。本页cs代码: protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databinding();
getinfo();
}
} protected void databinding()
{
JustyleOnline.Model.Product.Business.Product pro = new JustyleOnline.Model.Product.Business.Product();
DataSet ds= pro.GetNewProduct();
//string str = ds.Tables[0].Rows.Count.ToString();
//JustyleOnline.Core.JS.Alert(str);
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataBind();
}这是页面的数据绑定代码,其中获取到product的一些值。接下来是接受页面的代码: if (!Page.IsPostBack)
{
//显示更新数据
//若ID为空,则修改管理员自己的信息
if (Request.QueryString["ID"] == null)
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
}附:productID这个字段的数据类型是int型
求助各位!!!
<asp:DataList ID="DataList1" runat="server" Height="222px"
RepeatDirection="Horizontal" Width="756px" RepeatColumns="5" >
<ItemTemplate>
<a href="/Model/Product/ProductDetail.aspx?id=productID">
<img src='<%# DataBinder.Eval(Container.DataItem, "pic")%>' />
</a>
</ItemTemplate>
</asp:DataList>
这是用datalist绑定图片,然后他图片有个链接,然后传值过去。本页cs代码: protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databinding();
getinfo();
}
} protected void databinding()
{
JustyleOnline.Model.Product.Business.Product pro = new JustyleOnline.Model.Product.Business.Product();
DataSet ds= pro.GetNewProduct();
//string str = ds.Tables[0].Rows.Count.ToString();
//JustyleOnline.Core.JS.Alert(str);
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataBind();
}这是页面的数据绑定代码,其中获取到product的一些值。接下来是接受页面的代码: if (!Page.IsPostBack)
{
//显示更新数据
//若ID为空,则修改管理员自己的信息
if (Request.QueryString["ID"] == null)
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
}附:productID这个字段的数据类型是int型
求助各位!!!
解决方案 »
- .ASHX后缀文件有什么用???
- 左边一个TREEVIEW 点击节点,怎么把页加载进来?
- |M| 第三贴:如何在ASP.NET 中创建和删除SQL作业:大家来看看我的需求要怎么做
- [论]ASP.NET 2.0 Membership 扩展,请思归,孟子等各位大侠 ,再一发帖!!
- 如何在类文件中访问page对象?
- 忽然间连接数据库失败,不知道错哪里了 求高手!
- .net + flash 本地正常,服务器上传28M以下文件正常,再大点文件,报io错误
- 为什么执行我这个SQL语句的时候老出错?
- 很简单的问题
- 关于Attributes.Add()问题
- 页面缓存过大出错????
- 联动下拉菜单问题,在线急!
接受页面的那个判断语句,已经有判断是不是有接收到值。
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
}
应该这样写
if (Request.QueryString["id"] == null)
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["id"].ToString());
}
你这样传过去的值是productID,当然不能转换成int型了。。
<a href="/Model/Product/ProductDetail.aspx?id=<%=productID%>">试试而且
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());
你这里的ID要注意大小写,应该是一致的,即使没影响代码标准些有好处的。
1l兄,不好意思啊,你的代码可以,我用它解决了
咳咳,7l,你的那句“<%=productID%>”,貌似有些问题
OK,没事,都有分,虽然不多,大奖将就着吧
谢谢了