如果某个用户是第一次写入数据库,那么在页面上不会有数据显示.
必须再次打开页面才能显示数据.此时再添加数据就能正常显示了.
//写入User_product_more 用户商品详细表,
DateTime startime = DateTime.Now;
....
upmta.InsertUserProduct(...,startime,...)//写入数据库 ContextUtil.SetComplete();//提交事务
//帮定数据
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
this.odsUPmore.SelectParameters.Clear();
this.odsUPmore.SelectParameters.Add("uin", System.TypeCode.Int32, this.lbUin.Text);
this.dlKeyword.DataBind();
//Response.Redirect("managekeyword.aspx");//再次打开该页面,但是会出错
// Response.Write("<script>window.location.href='managekeyword.aspx';</script>");//用此脚本可以打开页面页面代码<asp:DataList ID="dlKeyword" runat="server" DataSourceID="odsUPmore" Width="770px"
ShowHeader="False" DataKeyField="up_id" RepeatColumns="3" RepeatDirection="Horizontal"
OnItemCommand="dlKeyword_EditCommand" OnPreRender="dlKeyword_PreRender">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="text-align: left; vertical-align: top;">
<%-- width: 250px;--%>
<tr>
<td style="width: 130px">
<asp:CheckBox ID="chkItem" runat="server"></asp:CheckBox>
<asp:Label ID="lbKeyword" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "up_name") %>'
Font-Size="12px"></asp:Label>
<%--<%# DataBinder.Eval(Container.DataItem, "up_name")%>--%>
</td>
<td>
<a href="info_revise.aspx?up_id=<%# Eval("up_id") %>" style="font-size: 12px" title="单击修改详细信息">
发布供应</a> </td>
</tr>
</table>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
<FooterTemplate>
<%-- --%>
<asp:CheckBox ID="chkHeader" runat="server" AutoPostBack="False" onclick="javascript:SelectAll(this);"
Text="全选/反选" /><%--//AutoPostBack设为假,不需要回发--%>
<asp:LinkButton ID="btDelete" runat="server" CommandName="delete" Text="删除" Visible="true"
OnClientClick="return confirm('确定删除?');" />
</FooterTemplate>
<FooterStyle HorizontalAlign="Left" />
</asp:DataList>
<asp:ObjectDataSource ID="odsUPmore" runat="server" OldValuesParameterFormatString="original_{0}"
TypeName="UserProductMoreTableAdapters.UPmoreProTableAdapter">
<%--SelectMethod="GetAllKeywordByUin"--%>
<SelectParameters>
<asp:ControlParameter ControlID="lbUin" DefaultValue="0" Name="uin" PropertyName="Text"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:Label ID="lbUin" runat="server" Visible="false"></asp:Label><!--接收后台的uin,传递给数据源,作为参数-->
必须再次打开页面才能显示数据.此时再添加数据就能正常显示了.
//写入User_product_more 用户商品详细表,
DateTime startime = DateTime.Now;
....
upmta.InsertUserProduct(...,startime,...)//写入数据库 ContextUtil.SetComplete();//提交事务
//帮定数据
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
this.odsUPmore.SelectParameters.Clear();
this.odsUPmore.SelectParameters.Add("uin", System.TypeCode.Int32, this.lbUin.Text);
this.dlKeyword.DataBind();
//Response.Redirect("managekeyword.aspx");//再次打开该页面,但是会出错
// Response.Write("<script>window.location.href='managekeyword.aspx';</script>");//用此脚本可以打开页面页面代码<asp:DataList ID="dlKeyword" runat="server" DataSourceID="odsUPmore" Width="770px"
ShowHeader="False" DataKeyField="up_id" RepeatColumns="3" RepeatDirection="Horizontal"
OnItemCommand="dlKeyword_EditCommand" OnPreRender="dlKeyword_PreRender">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="text-align: left; vertical-align: top;">
<%-- width: 250px;--%>
<tr>
<td style="width: 130px">
<asp:CheckBox ID="chkItem" runat="server"></asp:CheckBox>
<asp:Label ID="lbKeyword" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "up_name") %>'
Font-Size="12px"></asp:Label>
<%--<%# DataBinder.Eval(Container.DataItem, "up_name")%>--%>
</td>
<td>
<a href="info_revise.aspx?up_id=<%# Eval("up_id") %>" style="font-size: 12px" title="单击修改详细信息">
发布供应</a> </td>
</tr>
</table>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
<FooterTemplate>
<%-- --%>
<asp:CheckBox ID="chkHeader" runat="server" AutoPostBack="False" onclick="javascript:SelectAll(this);"
Text="全选/反选" /><%--//AutoPostBack设为假,不需要回发--%>
<asp:LinkButton ID="btDelete" runat="server" CommandName="delete" Text="删除" Visible="true"
OnClientClick="return confirm('确定删除?');" />
</FooterTemplate>
<FooterStyle HorizontalAlign="Left" />
</asp:DataList>
<asp:ObjectDataSource ID="odsUPmore" runat="server" OldValuesParameterFormatString="original_{0}"
TypeName="UserProductMoreTableAdapters.UPmoreProTableAdapter">
<%--SelectMethod="GetAllKeywordByUin"--%>
<SelectParameters>
<asp:ControlParameter ControlID="lbUin" DefaultValue="0" Name="uin" PropertyName="Text"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:Label ID="lbUin" runat="server" Visible="false"></asp:Label><!--接收后台的uin,传递给数据源,作为参数-->
解决方案 »
- dotnettextbox控件的问题
- webrequest下载页面,超时timeout,页面手动可以正常打开,什么原因??
- 验证视图状态 MAC 失败。
- “使用浏览器将用户重定向到另一页”和“使用服务器端方法将用户重定向到另一页”有什么不同啊
- 如何点击gridview任意位置获取当前行id到ViewState中
- 寻求最佳实现循环的方案???
- 紧急求助:这个异常看看大家有没有见过?
- 关于datagrid中checkbox的取值问题!!!给出解决方案,马上给分,在线等!!
- ***********************请问关于一个问题的解决方案,很有难度**************
- 大虾请进------
- 关于三层架构问题~
- 有两个div,调用hidediv 不能隐藏的问题。不明白,
把datalist的datasource重新绑定
dlKeyword.DataSourceID = "odsUPmore";
dlKeyword.DataBind();
一,在添加完的事件后,用Response.Redirect("本页名");//重新Redirect本页;
二,可以用Ajax;
{
DateTime startime = DateTime.Now;
....
upmta.InsertUserProduct(...,startime,...)//写入数据库 ContextUtil.SetComplete();//提交事务
//帮定数据
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
this.odsUPmore.SelectParameters.Clear();
this.odsUPmore.SelectParameters.Add("uin", System.TypeCode.Int32, this.lbUin.Text);
this.dlKeyword.DataBind(); }
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
this.odsUPmore.SelectParameters.Clear();
this.odsUPmore.SelectParameters.Add("uin", System.TypeCode.Int32, this.lbUin.Text);
this.dlKeyword.DataBind();
照样不行.
insus 我有写
//Response.Redirect("managekeyword.aspx");//再次打开该页面,但是会出错
Response.Write("<script>window.location.href='managekeyword.aspx';</script>");//用此脚本可以打开页面
Ajax不会,要如何写?
pxplyr_1984 我的代码是写在"protected void btnSubmit_Click(object sender, EventArgs e)"里的
这个能写在if (!this.IsPostBack) 中吗?不太明白.
实际上如果是第二次打开页面或打开时Datalist就有数据显示,那么此时添加数据,在代码运行结束后就能在页面上显示了.
第二:page_load里有什么代码
我看了这个页面的源文件果然没有Datalist生成的<table>.
这是有记录时页面的源文件<tr>
<td style="width: 20px">
</td>
<td style="width: 770px" colspan="2" class="manage_lm_border">
<span style="font-size: 14px"> 产品关键字</span>
<table id="dlKeyword" cellspacing="0" border="0" style="width:770px;border-collapse:collapse;">这个就是Datalist生成的table
<tr>
<td align="left">
<table border="0" cellpadding="0" cellspacing="0" style="text-align: left; vertical-align: top;">
<tr>
<td style="width: 130px">
<input id="dlKeyword_ctl00_chkItem" type="checkbox" name="dlKeyword$ctl00$chkItem" />
<span id="dlKeyword_ctl00_lbKeyword" style="font-size:12px;">fgg</span>
</td>
<td>
<a href="info_revise.aspx?up_id=146253" style="font-size: 12px" title="单击修改详细信息">
发布供应</a>
</td>
</tr>
</table>
</td><td></td><td></td>
</tr</table>
<!--接收后台的uin,传递给数据源,作为参数-->
</td>
</tr>
<!--现有关键字栏结束-->
这个是添加完记录后的源文件(Datalist里有记录的)<tr>
<td style="width: 20px">
</td>
<td style="width: 770px" colspan="2" class="manage_lm_border">
<span style="font-size: 14px"> 产品关键字</span> <span id="lblEmpty">您尚未创建产品关键字</span>
<!--接收后台的uin,传递给数据源,作为参数-->
</td>
</tr>
<!--现有关键字栏结束-->
{
int uin = 0;//用户编号
GetUin getuin = new GetUin();
if (getuin.GetName() != null && getuin.GetName().ToString().Trim() != "")
{
//返回uin,传给 控件的数据源 作为参数
uin = getuin.GetUinByName(getuin.GetName().ToString().Trim()); this.lbUin.Text = uin.ToString().Trim();//传递给数据源,作为参数
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
}
...
}
不能自动创建行云云没听过,至少我知道03是可以通过的,05不会越来越后退
{
this.dlKeyword.DataSourceID = "odsUPmore";
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
this.odsUPmore.SelectParameters.Clear();
this.odsUPmore.SelectParameters.Add("uin", System.TypeCode.Int32, this.lbUin.Text);
//this.dlKeyword.DataBind();//无论是否执行这行代码,Datalist里的记录数都不会改变,因为新记录尚未写入数据库 //判断有无关键字,并提示
if (this.dlKeyword.Items.Count <= 0)
{
this.dlKeyword.Visible = false;//此时Count为0,Datalist不可见.可问题是当运行完写入代码后,Datalist有记录了还是不可见
this.lblEmpty.Visible = true;
}
else
{
this.dlKeyword.Visible = true;
this.lblEmpty.Visible = false;
}
}于是我在写入后加了以下代码upmta.InsertUserProduct(...);
ContextUtil.SetComplete();//提交事务
this.DataBind();
this.dlKeyword.DataSourceID = "odsUPmore";
this.odsUPmore.SelectMethod = "GetAllKeywordByUin";
this.odsUPmore.SelectParameters.Clear();
this.odsUPmore.SelectParameters.Add("uin", System.TypeCode.Int32, this.lbUin.Text);
this.dlKeyword.DataBind();//判断有无关键字,并提示
if (this.dlKeyword.Items.Count <= 0)
{
this.dlKeyword.Visible = false;
this.lblEmpty.Visible = true;
}
else
{
this.dlKeyword.Visible = true;
this.lblEmpty.Visible = false;
}这样才行
{
//判断有无关键字,并提示
if (this.dlKeyword.Items.Count == 0)
{
this.dlKeyword.Visible = false;
this.lblEmpty.Visible = true;
}
else
{
this.dlKeyword.Visible = true;
this.lblEmpty.Visible = false;
}
}我原以为这个"dlKeyword_PreRender"可以在每次刷新后最后才执行到,那么就能判断出来是否显示了.
结果发现提交后并不会执行这段代码.这就造成了如果Datalist原先不可见的话,那么提交数据后依然不可见.
现在必须在每次修改纪录后用这个代码才判断出是否显示Datalist //判断有无关键字,并提示
if (this.dlKeyword.Items.Count == 0)
{
this.dlKeyword.Visible = false;
this.lblEmpty.Visible = true;
}
else
{
this.dlKeyword.Visible = true;
this.lblEmpty.Visible = false;
}
是否这么一个事件可以让我在页面上所有元素(各个控件,数据)都加载完成后在呈现给人看之前,使用上述办法来判断.
然后重新绑定Datalist
[align=left]if (this.dlKeyword.Items.Count == 0)
{
this.dlKeyword.Visible = false;
this.lblEmpty.Visible = true;
}
else
{
this.dlKeyword.Visible = true;
this.lblEmpty.Visible = false;
}[/align]