隐藏在gridview里面的特定单元格 [英] hide specific cells int he gridview which are inside table

查看:95
本文介绍了隐藏在gridview里面的特定单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用html表限制了网格视图中的值。每行包含html表和每页显示一个网格视图行。现在我想从第二行(第二个记录)开始隐藏一些单元格(复选框1,2,3,4)。这是粘贴在这里的巨大代码,我添加了一些示例代码..请帮助我...

I have bounded the values in the grid view using html table. Each row contains html table and one grid view row displayed per page. Now I wanted to hide some cells(checkbox 1,2,3,4) from second row (second record) onwards. It's huge code to paste here and I added some sample code.. Please help me out...

<asp:GridView ID="grdSampleForm" runat="server" AutoGenerateColumns="False" 

AllowPaging="True" AllowSorting="True" DataKeyNames="SampleID" DataSourceID="SqlDataSourceSampleFormDetails" PageSize="1" 

ForeColor="#333333" GridLines="None" CssClass="smallText" OnRowDataBound="grdSampleForm_RowDataBound" Width="100%"  OnRowUpdating="grdSampleForm_RowUpdating" OnRowCreated="grdSampleForm_RowCreated" >

     <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                <PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>

        <asp:TemplateField HeaderText="SampleForm Details">
            <ItemTemplate>

                <table style="font-size:x-small;" border="0" cellpadding="1" cellspacing="1">
                    <tr>
                        <td style="font-size:small;" colspan="2">Sample Date : <asp:Label ID="lblSampleDate" Text='<%# Eval("SampleDate", "{0:dd MMM yyyy}") %>' runat="server" /></td> 

                    </tr>
                    <tr>
                        <td><asp:CheckBox ID="CheckBox1" runat="server" Text="Sample1" Checked= '<%# Eval("Sample1") %>' Enabled="false"  TextAlign="Left" /></td>
                        <td><asp:CheckBox ID="CheckBox2" runat="server" Text="Sample2" Checked= '<%# Eval("Sample2") %>' Enabled="false"  TextAlign="Left" /></td>
                        <td><asp:CheckBox ID="CheckBox3" runat="server" Text="Sample3" Checked= '<%# Eval("Sample3") %>' Enabled="false"  TextAlign="Left" /></td>
                        <td><asp:CheckBox ID="CheckBox4" runat="server" Text="Sample4" Checked= '<%# Eval("Sample4") %>' Enabled="false"  TextAlign="Left" /></td>
                    </tr>
                    <tr>
                        <td colspan="2"><asp:CheckBox ID="CheckBox5" runat="server" Text="Sample5" Checked= '<%# Eval("Sample5") %>' Enabled="false" TextAlign="Left" /></td>
                        <td colspan="2">Sample Type : <asp:Label ID="lblSampleType" Text='<%# Eval("SampleTypeDesc")%>' runat="server" /></td>
                    </tr>

                    <tr>
                        <td><asp:CheckBox ID="CheckBox6" runat="server" Text="Sample6" Checked= '<%# Eval("Sample6") %>' Enabled="false"  TextAlign="Left" /></td>
                        <td><asp:CheckBox ID="CheckBox7" runat="server" Text="Sample7" Checked= '<%# Eval("Sample7") %>' Enabled="false"  TextAlign="Left" /></td>
                     </tr>

                </table>
            </ItemTemplate>

            <EditItemTemplate>
                <table style="font-size:small;" border="0" cellpadding="1" cellspacing="1">
                    <tr>
                        ...........
                        .........
                       </tr>
                </table>
            </EditItemTemplate>

        </asp:TemplateField>

              <asp:CommandField ShowEditButton="True" ButtonType="Image" ShowHeader="true" EditImageUrl="~/Images/database_edit.png" UpdateImageUrl="~/Images/database_save.png" CancelImageUrl="~/Images/cancel.png" ItemStyle-Width="5%" EditText="Edit">
              <ItemStyle  VerticalAlign="Bottom" />
              </asp:CommandField>

    </Columns>

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>

推荐答案

Quote:

I used c# code behind rowbound event and tried to find the row index but no luck..

I used c# code behind rowbound event and tried to find the row index but no luck..

You have to find the control inside the event so that you can hide because you are using TemplateFields.

You have to find the control inside the event so that you can hide because you are using TemplateFields.

var checkbox = e.Row.FindControl("CheckBoxID") as CheckBox;
checkbox.Visible = false;


这篇关于隐藏在gridview里面的特定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆