Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai Friends,

I am using formview in asp.net, the problem is editmode not working.When i click on the edit link button formview disappear.
Please help me to solve the error.

My design code

ASP.NET
<asp:FormView ID="FormView1" runat="server" DataKeyNames="HID"
    onitemcommand="FormView1_ItemCommand1">
<ItemTemplate>
<table>
<tr>
<td>HID</td><td><%# Eval("HID") %></td>
<td>UID</td><td><%# Eval("UID") %></td>
<td>HouseNo</td><td><%# Eval("HouseId") %></td>
<td>Status</td><td><%# Eval("Status") %></td>
<td>Category</td><td><%# Eval("Category")%></td>

</tr>
    <tr>
<td>HouseName</td><td><%# Eval("HouseName") %></td>
<td>ChurchName</td><td><%# Eval("FullHouseName") %></td>
<td>Malayalam</td><td><%# Eval("FullHouseNameMal")%></td>
</tr>

   <tr>
<td>Address1</td><td><%# Eval("Address1") %></td>
<td>Adddess2</td><td><%# Eval("Address2") %></td>
<td>Road</td><td><%# Eval("Road")%></td>
</tr>

     <tr>
<td>Pincode</td><td><%# Eval("Pincode")%></td>
<td>Landphone</td><td><%# Eval("Landphone")%></td>
<td>Date of join</td><td><%# Eval("DateOfJoin")%></td>
</tr>
    <tr>
        <td colspan="2">
           <asp:LinkButton ID="LinkButton1"
               runat="server" CommandName="EditInfo"
               Text="Edit">Edit</asp:LinkButton>
        </td>
    </tr>
</table>

</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>HID</td><td><%# Eval("HID") %></td>
<td>UID</td><td><%# Eval("UID") %></td>
<td>HouseNo</td><td><%# Eval("HouseId") %></td>
<td>Status</td><td><%# Eval("Status") %></td>
<td>Category</td><td><%# Eval("Category")%></td>

</tr>
    <tr>
<td>HouseName</td><td><asp:TextBox ID="txtHname" runat="server" Text='<%# Eval("HouseName") %>' /></td>
<td>ChurchName</td><td><%# Eval("FullHouseName") %></td>
<td>Malayalam</td><td><%# Eval("FullHouseNameMal")%></td>
</tr>

   <tr>
<td>Address1</td><td><%# Eval("Address1") %></td>
<td>Adddess2</td><td><%# Eval("Address2") %></td>
<td>Road</td><td><%# Eval("Road")%></td>
</tr>

     <tr>
<td>Pincode</td><td><%# Eval("Pincode")%></td>
<td>Landphone</td><td><%# Eval("Landphone")%></td>
<td>Date of join</td><td><%# Eval("DateOfJoin")%></td>
</tr>
<tr>
                  <td colspan="2">
                   <asp:LinkButton ID="LinkButton2"
        runat="server" CommandName="UpdateInfo"
        Text="UpdateInfo">Update</asp:LinkButton>
      <asp:LinkButton ID="LinkButton3"
        runat="server" CommandName="CancelUpdate"
        Text="CancelInfo">Cancel</asp:LinkButton>
                  </td>
                </tr>

</table>

</EditItemTemplate>
</asp:FormView>


C#
protected void FormView1_ItemCommand1(object sender, FormViewCommandEventArgs e)
   {
       switch (e.CommandName)
       {
           case "EditInfo":
               FormView1.ChangeMode(FormViewMode.Edit);
               break;
           case "CancelUpdate":
               FormView1.ChangeMode(FormViewMode.ReadOnly);
               break;
           case "CancelInsert":
               FormView1.ChangeMode(FormViewMode.ReadOnly);
               break;
           default:
               break;
       }

       FormView1.DataBind();
   }


Thanks in advance
Posted
Comments
Richard Deeming 2-Oct-14 10:26am    
You haven't set a DataSourceID, and the code you've posted doesn't set the DataSource property. If you try to bind the control without a data source, there will be nothing to display.
jinesh sam 2-Oct-14 10:41am    
i am binding with the help of this function

private void BindData_House()
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from House where HouseId=" + hno;
FormView1.DataSource = da.GetDataCommon(cmd);
FormView1.DataBind();
}
its works in readonly mode
Richard Deeming 2-Oct-14 11:28am    
But your FormView1_ItemCommand event handler isn't calling that method. You're trying to data-bind a control without setting the data source, which is why it disappears.
[no name] 7-Oct-14 0:32am    
+5
jinesh sam 2-Oct-14 13:01pm    
Thanks.. its works fine...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900