what i want to do is that when the gridview is populated i can only edit the fields that saids "YES" and that fields that said "NO" hide them or disable them so the user can edit them any ideas or examples ?
Protected Sub GridView2_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing
Dim opt As TextBox = DirectCast(GridView2.Rows(e.NewEditIndex).Cells(6).FindControl("TextBox10"), TextBox)
If opt.Text = "NO" Then
GridView2.Columns(6).Visible = False
End If
End Sub
but im getting this error
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 121: Dim opt As TextBox = DirectCast(GridView2.Rows(e.NewEditIndex).Cells(6).FindControl("TextBox10"), TextBox)
Line 122:
Line 123: If opt.Text = "NO" Then
Line 124: GridView2.Columns(6).Visible = False
Line 125:
jibarra
Member
39 Points
50 Posts
Hide cells based on the data of the gridview
Dec 21, 2012 02:31 PM|LINK
hi team i have a query that filled my gridview and i get the results like this
NAME A B C N
JOE YES NO NO YES
i make the dridview fields templates
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="IDS" DataSourceID="SqlDataSource2" CellPadding="0" CellSpacing="1" ForeColor="#333333" Font-Size="9pt" Width="817px"> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <Columns> <asp:TemplateField ShowHeader="False"> <EditItemTemplate> <asp:LinkButton ID="LkB1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> <asp:ConfirmButtonExtender ID="LinkUp_ConfirmButtonExtender" runat="server" ConfirmText="Are you sure you want to update the item?" Enabled="True" TargetControlID="LkB1"> </asp:ConfirmButtonExtender> <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </EditItemTemplate> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="IDS" HeaderText="IDS" InsertVisible="False" ReadOnly="True" SortExpression="IDS" Visible="False" /> <asp:TemplateField HeaderText="A" SortExpression="A"> <ItemTemplate> <asp:Label ID="Label10" runat="server" Text='<%# Bind("A") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("A") %>' Width="45px"></asp:TextBox> </EditItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField HeaderText="B" SortExpression="B"> <EditItemTemplate> <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("B") %>' Width="55px"></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label8" runat="server" Text='<%# Bind("B") %>'></asp:Label> </ItemTemplate> <HeaderStyle Width="70px" /> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField HeaderText="C" SortExpression="C"> <EditItemTemplate> <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("C") %>' Width="55px"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#999999" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView>what i want to do is that when the gridview is populated i can only edit the fields that saids "YES" and that fields that said "NO" hide them or disable them so the user can edit them any ideas or examples ?
thanks :)
amosCabanban...
Member
441 Points
148 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 02:38 PM|LINK
oned_gk
All-Star
35724 Points
7294 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 02:39 PM|LINK
Suwandi - Non Graduate Programmer
jibarra
Member
39 Points
50 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 03:52 PM|LINK
y try this and nothin happen, im using VB.net
jibarra
Member
39 Points
50 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 03:52 PM|LINK
im new on this, where do i put this
Visible='<%# Eval("A") == "YES" ? True : False %>'
im suing VB
thanks
amosCabanban...
Member
441 Points
148 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 05:45 PM|LINK
jibarra
Member
39 Points
50 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 06:37 PM|LINK
im getting an error on == "YES" that siasds Expression Expected
and on :false im getting syntax error
jibarra
Member
39 Points
50 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 07:05 PM|LINK
Protected Sub GridView2_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing Dim opt As TextBox = DirectCast(GridView2.Rows(e.NewEditIndex).Cells(6).FindControl("TextBox10"), TextBox) If opt.Text = "NO" Then GridView2.Columns(6).Visible = False End If End Subbut im getting this error
-------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 121: Dim opt As TextBox = DirectCast(GridView2.Rows(e.NewEditIndex).Cells(6).FindControl("TextBox10"), TextBox) Line 122: Line 123: If opt.Text = "NO" Then Line 124: GridView2.Columns(6).Visible = False Line 125:any ideas
oned_gk
All-Star
35724 Points
7294 Posts
Re: Hide cells based on the data of the gridview
Dec 21, 2012 10:40 PM|LINK
Suwandi - Non Graduate Programmer