Conditional Gridview Edit Column Not Working

Discussion in 'ASP .Net Web Controls' started by Kristen, Aug 31, 2006.

  1. Kristen

    Kristen Guest

    I am trying to display an edit column in my gridview based on certain
    data conditions. It works fine until I do a post back else where on
    the page then the grid is redrawn and the edit column that was absent
    is now present. The conditional formating is set up such:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    GridView1.RowDataBound

    If e.Row.RowType = DataControlRowType.DataRow Then

    If Not DataBinder.Eval(e.Row.DataItem, "fee_cost_type_ID")
    Is DBNull.Value Then

    e.Row.Cells(4).Text = ""
    e.Row.Cells(5).Text = ""
    End If
    End If

    End Sub

    Here is the gridview:

    <asp:GridView ID="GridView1" runat="server"
    DataKeyNames="Workout_fac_ID" AutoGenerateColumns="False"
    OnRowCancelingEdit="GridView1_RowCancelingEdit"
    OnRowEditing="GridView1_RowEditing"
    OnRowUpdating="GridView1_RowUpdating"
    OnRowUpdated="GridView1_RowUpdated"
    OnRowDeleting="GridView1_RowDeleting" ShowFooter="True"
    OnRowCommand="GridView1_RowCommand" ><Columns>

    <asp:TemplateField HeaderText="ID" visible = "false">

    <ItemTemplate>

    <asp:Label ID="lblRecordID" runat="server" Text='<%#
    Bind("Workout_fac_ID") %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField >

    <ItemTemplate>

    </ItemTemplate>

    <FooterTemplate>

    <asp:Button ID="Btn_Add" runat="server" CommandName="AddFee" Text="Add"
    />

    </FooterTemplate>


    </asp:TemplateField>

    <asp:TemplateField HeaderText="Amount">

    <ItemTemplate>

    <asp:Label ID="lblFee" Text='<%# Eval("Amount") %>'
    runat="server"></asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="txtFee" Text='<%# Eval("Amount") %>'
    runat="server"></asp:TextBox>

    </EditItemTemplate>

    <FooterTemplate>

    <asp:TextBox ID="txtAddFee" runat="server"></asp:TextBox>

    </FooterTemplate>

    </asp:TemplateField>

    <asp:TemplateField HeaderText="Description">

    <ItemTemplate>

    <asp:Label ID="lblDescription" Text='<%# Eval("Description") %>'
    runat="server"></asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="txtDescription" Text='<%# Eval("Description") %>'
    runat="server"></asp:TextBox>

    </EditItemTemplate>

    <FooterTemplate>

    <asp:TextBox ID="txtAddDescription" runat="server"></asp:TextBox>

    </FooterTemplate>

    </asp:TemplateField>

    <asp:CommandField HeaderText="Edit" ShowEditButton="True" />

    <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />

    </Columns>

    </asp:GridView>

    Thanks
    Kristen, Aug 31, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,299
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  2. Keithb
    Replies:
    2
    Views:
    1,106
  3. Keith G Hicks
    Replies:
    3
    Views:
    735
    Keith G Hicks
    Feb 18, 2008
  4. Saubz

    GridView Edit Not Working

    Saubz, Sep 25, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    560
    Walter Wang [MSFT]
    Sep 26, 2006
  5. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    370
    Jaime Stuardo
    Apr 7, 2006
Loading...

Share This Page