Hi,

I am wondering if anyone can help me with a small problem I am having. I am populating a gridview from an oracle DB. I only want some of these columns to be editable so I am using the code below to try and acheive this. As you can see I only 3 of the 4 columns to be allowed to be edited. However, the strange problem I am getting is that the only row that will open for edit is the one I wish to stay closed, while the other 3 are remaining closed! I think I am just doing something stupid here, but I really cant see it. Also, the page seems to be loading slower than I would have thought it would. I am presuming this is because I am binding the grid for a 2nd time whenever I press edit. Are there any easier ways of doing this?

Kindest Regards
David.

<code>
<asp:GridView ID="GridView1" BackColor="#f1f1f1"
AutoGenerateColumns="false" DataKeyNames="category_code" ShowFooter="true"
Font-Size="Small" Font-Names="Verdana" runat="server" GridLines="None"
OnRowDataBound="GridView1_RowDataBound" OnRowEditing ="GridView1_RowEditing" BorderStyle="Outset" >
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("category_code") %>', 'one');">
<img id="imgdiv<%# Eval("category_code") %>" alt="Click to show/hide Orders for Customer <%# Eval("category_code") %>" width="9px" border="0" src="Images/plus.gif"/>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField ="category_code" headertext="Category Code" HeaderStyle-HorizontalAlign ="Left" />
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" Text='<%# Eval("description") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblDescription" Text='<%# Eval("description") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget Amt">
<ItemTemplate>
<asp:Label ID="lblBudgetAmt" Text='<%# Eval("budget_amt") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblBudgetAmt" Text='<%# Eval("budget_amt") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Payment Freq" >
<ItemTemplate>
<asp:Label ID="lblPayfreq" Text='<%# Eval("pay_freq") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblPayfreq" Text='<%# Eval("pay_freq") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="" ShowEditButton="true" />
.....
</code>

here is my VB code

<code>
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing

Dim Al As New ArrayList
Dim Dt As New DataSet()
GridView1.EditIndex = CInt(e.NewEditIndex)

Al.Add(ReturnDbParam("pc_cu_id", "Test"))
Al.Add(ReturnDbParam("pc_member_id", "test"))
Dt = GetDataset(Al, "pkdb_web_budgets.f_get_categories", "budgets")

Me.GridView1.DataSource = Dt.Tables("budgets")
Me.GridView1.DataBind()

End Sub
</code>

Well from what you have pasted it seems that instead of textboxes that will make the column editable, you have put label controls in the <EditItemTemplate></EditItemTemplate>
tags.

So replace the label controls with textbox and it should work fine.

Regarding the page loading slow, only put the following code in your rowediting event

GridView1.EditIndex = CInt(e.NewEditIndex)

Bind the gridview outside the IsPostBack condition check on Page Load itself.

That should make it fast.

Thanks a lot. Can you tell I am new to .net??

As regards the page loading quicker, would it be better practice for me to dump the original values of the grid into a dataset when the edit fires, and then bind the new editable grid from this new dataset? That way im only querying the DB once. The reason it may be slow for me is that my grid bind fires another procedure to bind another grid (in a master-detail type fashion).

david.

would it be better practice for me to dump the original values of the grid into a dataset when the edit fires, and then bind the new editable grid from this new dataset?

Well I haven't seen anybody doing this and for good reason, trust me.
This is in no way going to be better in performance and you will also face plenty of problems while updating.

my grid bind fires another procedure to bind another grid (in a master-detail type fashion).

Oh..ya if its a nested grid, then it will be slower.

ok. Thanks for your help!

david.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.