I am working on Repeater to perform insert, edit, update, delete in ASP.Net using C#.I want to perform CRUD on Columns "B_Title" and "B_Desc" for that purpose i add link button but,when i click to the edit button then it gives me Exception.
Description:n unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.
Source ErrorLine 64: {
Line 65: //Toggle Buttons.
Line 66: item.FindControl("lnkButtionEdit").Visible = !isEdit;
Line 67: item.FindControl("lnkButtionUpdate").Visible = isEdit;
Line 68: item.FindControl("lnkButtonCancel").Visible = isEdit;
This is my HTML Code
<%-- Main Blog Post--%>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="post-preview">
<h2 class="post-title">
Man must explore,
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("B_Title") %>'></asp:Label>
<asp:TextBox ID="txtTitle" runat="server" class="form-control" Text='<%# Eval("B_Title") %>'
Visible="false" />
</h2>
<h3 class="post-subtitle">
<asp:Label ID="lblDesc" runat="server" Text='<%#Eval("B_Desc") %>'></asp:Label>
<asp:TextBox ID="txtDesc" runat="server" class="form-control" Text='<%# Eval("B_Desc") %>' Visible="false" />
</h3>
<a><a href="<%#Eval("B_Category") %>/<%#Eval("B_URL")%>">Read the Complete Article</a></a>
<p class="post-meta">
Posted by
<a href="#">Start Bootstrap</a>
<%#Eval("B_Datetime","{0:MMMM dd,YYYY}") %><a href="<%#Eval("B_Category")%>/Home.aspx"><%#Eval("B_URL")%>
</p>
<asp:LinkButton ID="lnkButtonEdit" runat="server" OnClick="lnkButtonEdit_Click">Edit</asp:LinkButton>
<asp:LinkButton ID="lnkButtonUpdate" runat="server" OnClick="lnkButtonUpdate_Click" Visible="false">Update</asp:LinkButton>
<asp:LinkButton ID="lnkButtonDelete" runat="server" OnClick="lnkButtonDelete_Click" Visible="false">Delete</asp:LinkButton>
<asp:LinkButton ID="lnkButtonCancel" runat="server" OnClick="lnkButtonCancel_Click1">Cancel</asp:LinkButton>
</div>
This is my C# Code
private void ToggleElements(RepeaterItem item, bool isEdit)
{
item.FindControl("lnkButtionEdit").Visible = !isEdit;
item.FindControl("lnkButtionUpdate").Visible = isEdit;
item.FindControl("lnkButtonCancel").Visible = isEdit;
item.FindControl("lnkButtionDelete").Visible = !isEdit;
item.FindControl("lblTitle").Visible = !isEdit;
item.FindControl("lblDesc").Visible = !isEdit;
item.FindControl("txtTitle").Visible = isEdit;
item.FindControl("txtDesc").Visible = isEdit;
}
protected void lnkButtonEdit_Click(object sender, EventArgs e)
{
RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem;
this.ToggleElements(item, true);
}
it gives my exception on this line of code
item.FindControl("lnkButtionEdit").Visible = !isEdit;
What I have tried:
I have tried to solve this Issue, Kindly give me solution.