小弟 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次修改,而不覆盖原有编辑?是否可以可视化编辑?究竟怎么编辑呢?谢谢大家解答,写清步骤我会给分的谢谢

解决方案 »

  1.   

    页面的HTML代码写好了 不能直接更新到界面上显示效果吗?
      

  2.   

    不绑定数据是看不到效果的。你只能定义控件的Width和High固定位置。。看效果的话还是要编译
      

  3.   

    我不是要求看效果  我的意思是最少让我在那个地方看见 那个地方还有LABEL和BUTTON这个控件
      

  4.   

    我倒    LABEL控件看不到吗?
      

  5.   

    你的ItemTemplate中只有td没有table和tr?
      

  6.   

    楼主兄弟,显示问题你多调试几下,我的方法是先 删除一部分,留一部分再试,这样一直试。
    还有就是像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>多调试几次总会成功的!
      

  7.   

    呵呵,不编译着么能看到效果
    即使是LABEL。你后面的内容也要绑定才看到的哇
      

  8.   

    我晕了 我就说不明白了
    我的意思是  不要求看到他运行的效果,没绑定没数据当然没效果,这我知道
    我的意思是最少让我在他上面看见有个LABEL站位符号,最起码他里面有几个LABEL总该可以看到吧?就和那个往里面放控件的时候效果一样 ,这次要再说不明白我就彻底崩溃了  ,到底有高手没啊?   这个小技巧都没人会吗?     我晕
      

  9.   

    呵呵  还有这样的事?
    我从来没见过    DATALIST是可一修改的 呀
      
    你直接在设计里修改html代码    可以吗   
      

  10.   

     Text='<%Eval("productname") %>'
    检查你的单引号和多引号,反复的测试一下.这样的东西,在设计试图里有时候打不开.
    不建议这样写.
    最好写在DataList的OnCreate事件里.
      

  11.   

    Text='<%Eval("productid") %>'Text='<%#Eval("productid") %>'
      

  12.   

    你知道DataList的用法吗?确切说你的html代码部分,到呈现在IE中是否呈现出符合Table的html正确代码
    。我举个简单的运用例子    <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>
      

  13.   

     Sorry,上面的虽然没错误,但不符合正常的运用,
    应该是这样比较正确    <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>
      

  14.   

    LZ,应该是这样的:
    <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控件各个模板的含义吧。
      

  15.   

    UP  29,28楼说的  我一直就这么做的   都能显示  但是我在下面的EDITTEMPLATE下面上写就不能显示
    UP U P  
      

  16.   

    UP   补充下  我在编辑 EDITITEMPLATE的时候  他会覆盖掉原来的ITEMTEMPLATE不信 你们可以做做看   而且EditTemplte不显示  ,不应该啊
    你去界面上点编辑模板 下面有下拉框  可以平铺3个窗体,你都可以直接拖放控件进去,然后再进HTML修改代码,但是你编辑后再回来,在点编辑模板就什么都不看了,我  倒   @!@!这个问题不可能大家都没碰到过吧?   这个肯定是有技巧的,不可能微软做出来的这个编辑既然设计成可视化,又不让用可视化?大家认为微软真的会这么垃圾吗?不可能的???
    求技巧
      

  17.   

    我都试过了没问题的...你的table标签确定都放到一个模板里了吗?红色代码显示的
    我在“源”里手动添加代码后返回“设计”视图,查看“编辑模板”里的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>