Conditional Gridview Edit Column Not Working

K

Kristen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top