Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview with an edit Commandfield. It is bound to table Asset_Portfolio. Works fine. I click on EDIT, it gives me UPDATE and CANCEL links. I input a few exposed fields and click UPDATE. It updates.

Now I add a couple dropdowns on the panel outside of the gridview. I populate them and when the user clicks on a row, it sends that row to the gridview where. That part works great. However, the dropdowns are somehow preventing the Gridview from allowing an EDIT. I click on EDIT, the text boxes appear, but it won't let me enter any data.
I played around with this a bit and discovered that before the dropdowns are bound, the EDIT works correctly. Once the DataBind command executes, the gridview is broken.

Can someone please help me? No idea.

What I have tried:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"  PageSize="37" AllowSorting="True"
      AlternatingRowStyle-BackColor="#99CCFF"
      DataSourceID="dsPortfolio" AutoGenerateColumns="False"
      DataKeyNames="Asset_Id" OnRowDataBound="OnRowDataBound" OnRowUpdating="OnRowUpdating"
      EnableUpdate="true"
      Height="100%"
      Width="100%">
      <AlternatingRowStyle BackColor="#cccccc" />


      <Columns>
                     <asp:CommandField ShowEditButton="True"

          ButtonType="Link" EditText="EDIT"
          UpdateText="UPDATE"
          CancelText="CANCEL">
      </asp:CommandField>

          <asp:BoundField DataField="Asset_Id" HeaderText="ID" ReadOnly="True" SortExpression="Asset_Id" ItemStyle-Width="10px"/>
           <asp:BoundField DataField="As_Of_Date" HeaderText="AsOf" ReadOnly="True" SortExpression="As_Of_Date" ItemStyle-Width="200px"/>
          <asp:BoundField DataField="Loan_Number_Display" HeaderText="Loan #" ReadOnly="True" SortExpression="Loan_Number_Display" ItemStyle-Width="100px"/>
          <asp:BoundField DataField="Entity_Name" HeaderText="Name" ReadOnly="True" SortExpression="Entity_Name" ItemStyle-Width="200px"/>



SqlDataAdapter da2 = new SqlDataAdapter("select distinct loan_number_display from libor.Droploan order by loan_number_display", Conn3);
  DataSet ds2 = new DataSet();
  da2.Fill(ds2);
  if (ddlLoan != null)
  {
      ddlLoan.DataSource = ds2;
      ddlLoan.DataTextField = "Loan_number_display";
      ddlLoan.DataValueField = "Loan_number_display";
      ddlLoan.Items.Insert(0, new ListItem("Select"));
      ddlLoan.DataBind();

  }
  da2.Dispose();
  ds2.Dispose();
Posted
Updated 28-Feb-20 7:01am
Comments
ZurdoDev 27-Feb-20 11:29am    
I'm not sure how to help you without seeing what is going on.

1 solution

Doesn't make sense to use a DataSet as a binding source, and then to "Dispose" it.
if (ddlLoan != null)
  {
      ddlLoan.DataSource = ds2;
      ddlLoan.DataTextField = "Loan_number_display";
      ddlLoan.DataValueField = "Loan_number_display";
      ddlLoan.Items.Insert(0, new ListItem("Select"));
      ddlLoan.DataBind();

  }
  da2.Dispose();
  ds2.Dispose();
 
Share this answer
 
Comments
Richard Deeming 28-Feb-20 14:18pm    
This is ASP.NET; once the DataBind method returns, there won't be any link between the bound items and the DataSet, so disposing of it won't hurt.

What doesn't make sense to me is loading the data outside of the if block when it's only used inside that block.

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