listview项目之间的空白区域

时间:2014-04-04 15:23:32

标签: c# asp.net listview

我有一个连接到sqlserver的listview但是listview的列显示没有任何空格。我想在表格中添加像表格中的cellpadding这样的功能。 我的代码:

<asp:ListView ID="ListView1" runat="server" DataKeyNames="DarkhastId" 
            DataSourceID="SqlDataSource1" GroupItemCount="2">

            <AlternatingItemTemplate>
                <td runat="server" style="">
                    DarkhastId:
                    <asp:Label ID="DarkhastIdLabel" runat="server" 
                        Text='<%# Eval("DarkhastId") %>' />
                    <br />
                    shakhs:
                    <asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
                    <br />
                    nam:
                    <asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
                    <br />
                    Idgharardad:
                    <asp:Label ID="IdgharardadLabel" runat="server" 
                        Text='<%# Eval("Idgharardad") %>' />
                    <br />
                    elat:
                    <asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
                    <br />
                    hamrah:
                    <asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
                    <br />
                    sabet:
                    <asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
                    <br />
                    vaziat:
                    <asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
                    <br />
                    karshenas:
                    <asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
                    <br />
                    tarikh:
                    <asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
                    <br />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <br />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    <br />
                </td>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <td runat="server" style="">
                    DarkhastId:
                    <asp:Label ID="DarkhastIdLabel1" runat="server" 
                        Text='<%# Eval("DarkhastId") %>' />
                    <br />
                    shakhs:
                    <asp:TextBox ID="shakhsTextBox" runat="server" Text='<%# Bind("shakhs") %>' />
                    <br />
                    nam:
                    <asp:TextBox ID="namTextBox" runat="server" Text='<%# Bind("nam") %>' />
                    <br />
                    Idgharardad:
                    <asp:TextBox ID="IdgharardadTextBox" runat="server" 
                        Text='<%# Bind("Idgharardad") %>' />
                    <br />
                    elat:
                    <asp:TextBox ID="elatTextBox" runat="server" Text='<%# Bind("elat") %>' />
                    <br />
                    hamrah:
                    <asp:TextBox ID="hamrahTextBox" runat="server" Text='<%# Bind("hamrah") %>' />
                    <br />
                    sabet:
                    <asp:TextBox ID="sabetTextBox" runat="server" Text='<%# Bind("sabet") %>' />
                    <br />
                    vaziat:
                    <asp:TextBox ID="vaziatTextBox" runat="server" Text='<%# Bind("vaziat") %>' />
                    <br />
                    karshenas:
                    <asp:TextBox ID="karshenasTextBox" runat="server" 
                        Text='<%# Bind("karshenas") %>' />
                    <br />
                    tarikh:
                    <asp:TextBox ID="tarikhTextBox" runat="server" Text='<%# Bind("tarikh") %>' />
                    <br />
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" />
                    <br />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" />
                    <br />
                </td>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table runat="server" style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <EmptyItemTemplate>
                <td runat="server" />
            </EmptyItemTemplate>
            <GroupTemplate>
                <tr ID="itemPlaceholderContainer" runat="server">
                    <td ID="itemPlaceholder" runat="server">
                    </td>
                </tr>
            </GroupTemplate>
            <InsertItemTemplate>
                <td runat="server" style="">
                    shakhs:
                    <asp:TextBox ID="shakhsTextBox" runat="server" Text='<%# Bind("shakhs") %>' />
                    <br />
                    nam:
                    <asp:TextBox ID="namTextBox" runat="server" Text='<%# Bind("nam") %>' />
                    <br />
                    Idgharardad:
                    <asp:TextBox ID="IdgharardadTextBox" runat="server" 
                        Text='<%# Bind("Idgharardad") %>' />
                    <br />
                    elat:
                    <asp:TextBox ID="elatTextBox" runat="server" Text='<%# Bind("elat") %>' />
                    <br />
                    hamrah:
                    <asp:TextBox ID="hamrahTextBox" runat="server" Text='<%# Bind("hamrah") %>' />
                    <br />
                    sabet:
                    <asp:TextBox ID="sabetTextBox" runat="server" Text='<%# Bind("sabet") %>' />
                    <br />
                    vaziat:
                    <asp:TextBox ID="vaziatTextBox" runat="server" Text='<%# Bind("vaziat") %>' />
                    <br />
                    karshenas:
                    <asp:TextBox ID="karshenasTextBox" runat="server" 
                        Text='<%# Bind("karshenas") %>' />
                    <br />
                    tarikh:
                    <asp:TextBox ID="tarikhTextBox" runat="server" Text='<%# Bind("tarikh") %>' />
                    <br />
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Insert" />
                    <br />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                    <br />
                </td>
            </InsertItemTemplate>

            <ItemTemplate>
                <td runat="server" style="">
                    DarkhastId:
                    <asp:Label ID="DarkhastIdLabel" runat="server" 
                        Text='<%# Eval("DarkhastId") %>' />
                    <br />
                    shakhs:
                    <asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
                    <br />
                    nam:
                    <asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
                    <br />
                    Idgharardad:
                    <asp:Label ID="IdgharardadLabel" runat="server" 
                        Text='<%# Eval("Idgharardad") %>' />
                    <br />
                    elat:
                    <asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
                    <br />
                    hamrah:
                    <asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
                    <br />
                    sabet:
                    <asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
                    <br />
                    vaziat:
                    <asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
                    <br />
                    karshenas:
                    <asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
                    <br />
                    tarikh:
                    <asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
                    <br />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <br />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    <br />
                </td>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server">
                    <tr runat="server">
                        <td runat="server">
                            <table ID="groupPlaceholderContainer" runat="server" border="0" style="">
                                <tr ID="groupPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr runat="server">
                        <td runat="server" style="">
                            <asp:DataPager ID="DataPager1" runat="server" PageSize="12">
                                <Fields>
                                    <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                        ShowLastPageButton="True" />
                                </Fields>
                            </asp:DataPager>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <td runat="server" style="">
                    DarkhastId:
                    <asp:Label ID="DarkhastIdLabel" runat="server" 
                        Text='<%# Eval("DarkhastId") %>' />
                    <br />
                    shakhs:
                    <asp:Label ID="shakhsLabel" runat="server" Text='<%# Eval("shakhs") %>' />
                    <br />
                    nam:
                    <asp:Label ID="namLabel" runat="server" Text='<%# Eval("nam") %>' />
                    <br />
                    Idgharardad:
                    <asp:Label ID="IdgharardadLabel" runat="server" 
                        Text='<%# Eval("Idgharardad") %>' />
                    <br />
                    elat:
                    <asp:Label ID="elatLabel" runat="server" Text='<%# Eval("elat") %>' />
                    <br />
                    hamrah:
                    <asp:Label ID="hamrahLabel" runat="server" Text='<%# Eval("hamrah") %>' />
                    <br />
                    sabet:
                    <asp:Label ID="sabetLabel" runat="server" Text='<%# Eval("sabet") %>' />
                    <br />
                    vaziat:
                    <asp:Label ID="vaziatLabel" runat="server" Text='<%# Eval("vaziat") %>' />
                    <br />
                    karshenas:
                    <asp:Label ID="karshenasLabel" runat="server" Text='<%# Eval("karshenas") %>' />
                    <br />
                    tarikh:
                    <asp:Label ID="tarikhLabel" runat="server" Text='<%# Eval("tarikh") %>' />
                    <br />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <br />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    <br />
                </td>
            </SelectedItemTemplate>
        </asp:ListView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:akhbarrrConnectionString %>" 
            DeleteCommand="DELETE FROM [darkhastezam] WHERE [DarkhastId] = @DarkhastId" 
            InsertCommand="INSERT INTO [darkhastezam] ([shakhs], [nam], [Idgharardad], [elat], [hamrah], [sabet], [vaziat], [karshenas], [tarikh]) VALUES (@shakhs, @nam, @Idgharardad, @elat, @hamrah, @sabet, @vaziat, @karshenas, @tarikh)" 
            SelectCommand="SELECT * FROM [darkhastezam]" 
            UpdateCommand="UPDATE [darkhastezam] SET [shakhs] = @shakhs, [nam] = @nam, [Idgharardad] = @Idgharardad, [elat] = @elat, [hamrah] = @hamrah, [sabet] = @sabet, [vaziat] = @vaziat, [karshenas] = @karshenas, [tarikh] = @tarikh WHERE [DarkhastId] = @DarkhastId">
            <DeleteParameters>
                <asp:Parameter Name="DarkhastId" Type="Decimal" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="shakhs" Type="String" />
                <asp:Parameter Name="nam" Type="String" />
                <asp:Parameter Name="Idgharardad" Type="Decimal" />
                <asp:Parameter Name="elat" Type="String" />
                <asp:Parameter Name="hamrah" Type="String" />
                <asp:Parameter Name="sabet" Type="String" />
                <asp:Parameter Name="vaziat" Type="String" />
                <asp:Parameter Name="karshenas" Type="String" />
                <asp:Parameter Name="tarikh" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="shakhs" Type="String" />
                <asp:Parameter Name="nam" Type="String" />
                <asp:Parameter Name="Idgharardad" Type="Decimal" />
                <asp:Parameter Name="elat" Type="String" />
                <asp:Parameter Name="hamrah" Type="String" />
                <asp:Parameter Name="sabet" Type="String" />
                <asp:Parameter Name="vaziat" Type="String" />
                <asp:Parameter Name="karshenas" Type="String" />
                <asp:Parameter Name="tarikh" Type="String" />
                <asp:Parameter Name="DarkhastId" Type="Decimal" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>

3 个答案:

答案 0 :(得分:1)

你能添加cellspacing属性吗?

<LayoutTemplate>
    <table runat="server" cellspacing="5">

答案 1 :(得分:1)

我建议添加css样式:

例如这个项目,虽然这是一个按钮:

  

<asp:Button ID="CancelButton" runat="server" style="padding:15px;" CommandName="Cancel" Text="Clear" />

还可以看到http://msdn.microsoft.com/en-us/library/9wx8w7we的css类

答案 2 :(得分:1)

  1. 将CssClass添加到所有表标签
  2. <table class="test" ...
    
    1. 创建内联样式(或外部)。您可以将样式更改为符合您需要的边距或填充顶部/填充底部。

       table.test td {      填充:3px;  }