小弟 ASP.NET出道,来看问题 工具VS2005 现象:
我用DATALIST控件,但是我在点设计的时候去里面写HTML代码的代码如下
<ItemTemplate>
<td>
<asp:Label ID="Label1" runat="server" Text='<%Eval("productid") %>'></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text='<%Eval("productname") %>'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%Eval("UnitPrice") %>'></asp:Label></td>
<td><asp:Button ID="Button1" runat="server" Text="编辑" />
</td>
</ItemTemplate>
然后我又点了设计 想去界面上看看我的ITEMTEMPLATE下面的图什么样子,结果点了控件的编辑模板,然后选择了ITEMTEPLATE下面缺看不到图,结果我右添加了几个控件,结果还把我刚才添加的控件给覆盖了,我晕了,难道必须一次编辑完毕吗? 不能再次修改吗?我的操作究竟是那里的问题呢? 我刚开始要是直接拖放控件进去,第2次再编辑ITEMTEMPLATE他还是覆盖第1次的,我的问题是: 我怎么对DATALIST进行2次修改,而不覆盖原有编辑?是否可以可视化编辑?究竟怎么编辑呢?谢谢大家解答,写清步骤我会给分的谢谢
我用DATALIST控件,但是我在点设计的时候去里面写HTML代码的代码如下
<ItemTemplate>
<td>
<asp:Label ID="Label1" runat="server" Text='<%Eval("productid") %>'></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text='<%Eval("productname") %>'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%Eval("UnitPrice") %>'></asp:Label></td>
<td><asp:Button ID="Button1" runat="server" Text="编辑" />
</td>
</ItemTemplate>
然后我又点了设计 想去界面上看看我的ITEMTEMPLATE下面的图什么样子,结果点了控件的编辑模板,然后选择了ITEMTEPLATE下面缺看不到图,结果我右添加了几个控件,结果还把我刚才添加的控件给覆盖了,我晕了,难道必须一次编辑完毕吗? 不能再次修改吗?我的操作究竟是那里的问题呢? 我刚开始要是直接拖放控件进去,第2次再编辑ITEMTEMPLATE他还是覆盖第1次的,我的问题是: 我怎么对DATALIST进行2次修改,而不覆盖原有编辑?是否可以可视化编辑?究竟怎么编辑呢?谢谢大家解答,写清步骤我会给分的谢谢
还有就是像DATALIST 这样绑定数据源控件提供了现成的编辑、删除等功能,比如
<asp:LinkButton ID="LinkButton1" Text="编辑" CommandName="Edit" runat="server"></asp:LinkButton>
只是在DATALIST 中加入OnEditCommand="DataList1_EditCommand" 这样的属性,然后再写函数可以了
这个就可以来替代你的
<td><asp:Button ID="Button1" runat="server" Text="编辑" /></td>多调试几次总会成功的!
即使是LABEL。你后面的内容也要绑定才看到的哇
我的意思是 不要求看到他运行的效果,没绑定没数据当然没效果,这我知道
我的意思是最少让我在他上面看见有个LABEL站位符号,最起码他里面有几个LABEL总该可以看到吧?就和那个往里面放控件的时候效果一样 ,这次要再说不明白我就彻底崩溃了 ,到底有高手没啊? 这个小技巧都没人会吗? 我晕
我从来没见过 DATALIST是可一修改的 呀
你直接在设计里修改html代码 可以吗
检查你的单引号和多引号,反复的测试一下.这样的东西,在设计试图里有时候打不开.
不建议这样写.
最好写在DataList的OnCreate事件里.
。我举个简单的运用例子 <asp:DataList ID="objList" runat="server">
<HeaderTemplate>
<table >
<tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:Label ID="Label1" runat="server" Text='<%Eval("productid") %>'></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text='<%Eval("productname") %>'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%Eval("UnitPrice") %>'></asp:Label></td>
<td><asp:Button ID="Button1" runat="server" Text="编辑" />
</td>
</ItemTemplate>
<FooterTemplate>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
应该是这样比较正确 <asp:DataList ID="objList" runat="server">
<HeaderTemplate>
<table >
</HeaderTemplate>
<ItemTemplate>
<tr> <td>
<asp:Label ID="Label1" runat="server" Text='<%Eval("productid") %>'></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text='<%Eval("productname") %>'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%Eval("UnitPrice") %>'></asp:Label></td>
<td><asp:Button ID="Button1" runat="server" Text="编辑" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
<ItemTemplate>
<table>
<tr>
<td><asp:Label ID="Label1" runat="server" Text='<%Eval("productid") %>'></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text='<%Eval("productname") %>'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%Eval("UnitPrice") %>'></asp:Label></td>
<td><asp:Button ID="Button1" runat="server" Text="编辑" /></td>
</tr>
</table>
</ItemTemplate>然后编辑模板就能看到你想要的结果了
不要把table标签对拆开分散到<headerTemplate>和<footerTemplate>里,LZ再看看DataList控件各个模板的含义吧。
UP U P
你去界面上点编辑模板 下面有下拉框 可以平铺3个窗体,你都可以直接拖放控件进去,然后再进HTML修改代码,但是你编辑后再回来,在点编辑模板就什么都不看了,我 倒 @!@!这个问题不可能大家都没碰到过吧? 这个肯定是有技巧的,不可能微软做出来的这个编辑既然设计成可视化,又不让用可视化?大家认为微软真的会这么垃圾吗?不可能的???
求技巧
我在“源”里手动添加代码后返回“设计”视图,查看“编辑模板”里的4个区域显示正常。
我的测试代码:
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="123"> </asp:Label> </td>
<td> <asp:Button ID="Button1" runat="server" Text="编辑" /> </td>
</tr>
</table>
</ItemTemplate>
<AlternatingItemTemplate>
<asp:Label ID="Label1" runat="server" Text="123"> </asp:Label>
<asp:Button ID="Button2" runat="server" Text="Button" />
</AlternatingItemTemplate>
<SelectedItemTemplate>
<asp:Label ID="Label1" runat="server" Text="123"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</SelectedItemTemplate>
<EditItemTemplate>
<table border="1">
<tr> <td><asp:Label ID="Label1" runat="server" Text="123"> </asp:Label>
</td>
<td><asp:Image ID="Image1" runat="server" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:DataList>