Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
If e.Row.RowState = DataControlRowState.Edit Then
            e.Row.Cells(0).Controls(1).Visible = False

        End If


Here is more code
VB
Protected Sub Projects_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles Projects.RowCreated
'display only the first,third, fifth.. I need to display all rows first,second,third...
    If e.Row.RowState = DataControlRowState.Edit Then
        e.Row.Cells(0).Controls(1).Visible = False
    End If

    'This one is working
    If e.Row.RowType = DataControlRowType.DataRow Then
        For Each cell As TableCell In e.Row.Cells
            e.Row.Cells(2).Enabled = False
            e.Row.Cells(4).Enabled = False
            e.Row.Cells(5).Enabled = False
            e.Row.Cells(6).Enabled = False
            e.Row.Cells(7).Enabled = False
        Next
    End If

End Sub


XML
<asp:GridView ID="Projects" runat="server" AutoGenerateColumns="False" DataKeyNames="ProjectID" width="75%">
 <columns>
 <asp:TemplateField HeaderText="ProjectID" Visible="false">
 <itemtemplate>
 <asp:Label ID="lblProjectID" runat="server" Text='<%# Bind("ProjectID") %>'></asp:Label>
 </itemtemplate>
 </asp:TemplateField>
 <asp:BoundField DataField="Name" HeaderText="Project Number" ReadOnly="true" />
 <asp:BoundField DataField="Address" DataFormatString="{0:C}" HeaderText=" Funding" />
 <asp:BoundField DataField="Local" DataFormatString="{0:C}" HeaderText="Local" />
 <asp:BoundField DataField="Voluntary_Contribution" DataFormatString="{0:C}" HeaderText="Voluntary Contribution" />
 <asp:BoundField DataField="Total" DataFormatString="{0:C}" HeaderText="Total"
 ReadOnly="True" />
 <asp:CommandField ShowEditButton="True" />
 </columns>
 <HeaderStyle CssClass="GridHeader" />
 </asp:GridView>
Posted
Updated 13-Jun-15 3:08am
v2
Comments
virusstorm 12-Jun-15 14:19pm    
You need to post more code for us to help you. How is the code you posted being executed?
Member 11759154 12-Jun-15 14:35pm    
Here is more code
<pre lang="vb">Protected Sub Projects_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles Projects.RowCreated
display only the first,third, fifth.. I need to display all rows first,second,third...
If e.Row.RowState = DataControlRowState.Edit Then
e.Row.Cells(0).Controls(1).Visible = False

End If
//This one is working
If e.Row.RowType = DataControlRowType.DataRow Then
For Each cell As TableCell In e.Row.Cells
e.Row.Cells(2).Enabled = False
e.Row.Cells(4).Enabled = False
e.Row.Cells(5).Enabled = False
e.Row.Cells(6).Enabled = False
e.Row.Cells(7).Enabled = False
Next
End If

End Sub</pre>

<pre lang="xml"><asp:GridView ID="Projects" runat="server" AutoGenerateColumns="False" DataKeyNames="ProjectID" width="75%">
<columns>
<asp:TemplateField HeaderText="ProjectID" Visible="false">
<itemtemplate>
<asp:Label ID="lblProjectID" runat="server" Text='<%# Bind("ProjectID") %>'></asp:Label>
</itemtemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Project Number" ReadOnly="true" />
<asp:BoundField DataField="Address" DataFormatString="{0:C}" HeaderText=" Funding" />
<asp:BoundField DataField="Local" DataFormatString="{0:C}" HeaderText="Local" />
<asp:BoundField DataField="Voluntary_Contribution" DataFormatString="{0:C}" HeaderText="Voluntary Contribution" />
<asp:BoundField DataField="Total" DataFormatString="{0:C}" HeaderText="Total"
ReadOnly="True" />
<asp:CommandField ShowEditButton="True" />
</columns>
<HeaderStyle CssClass="GridHeader" />
</asp:GridView></pre>
Arkadeep De 13-Jun-15 2:03am    
put that code in RowDataBond event of GridView
Member 11759154 13-Jun-15 11:23am    
I did in GridView1_RowDataBound(....) still the same

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900