Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm Opening Fancybox on Repeater' Row Edit linkButton n updating content i want to show label text as "Updated" after the execution of Update Query.But Don't Know whats wrong with this code Label text is not showing after Updation can anyone help me out ?
thanks in advance.

C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Thread.Sleep(3000);
        //foreach (RepeaterItem item2 in Repeater1.Items)
        //{
            TextBox name = (TextBox)e.Item.FindControl("TextBox1");
            TextBox address = (TextBox)e.Item.FindControl("TextBox2");
            //Label lbl = (Label)e.Item.FindControl("Label1");


            if (e.CommandName == "Edit")
            {
                int p_id = Convert.ToInt32(e.CommandArgument);
                SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
                SqlCommand sqlcomm = new SqlCommand("Update persons set p_name='" +name.Text +"' , p_address='" + address.Text + "'  where p_id='" + p_id + "'", sqlconn);
                sqlconn.Open();
                sqlcomm.ExecuteNonQuery();
                
                sqlconn.Close();
                //lbl.Text = "Updated";
                Label1.Text = "updated";
                
                
                Bind();
                

                
                


            }
            
            
        //}
        
    }


ASPX part-

ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
        <asp:Repeater ID="Repeater1" runat="server" 
            onitemcommand="Repeater1_ItemCommand">
        
         <HeaderTemplate>
        <table cellpadding="5px" style="margin-removed600px;margin-removed200px">
       <th>ID</th><th>Name</th><th>Address</th><th>Edit</th>
        
        </HeaderTemplate>
        <ItemTemplate>
       <tr> <td><%#Eval("p_id") %></td><td><%#Eval("p_name") %></td><td><%#Eval("p_address") %></td><td>
           <asp:LinkButton ID="LinkButton1"  runat="server" class="modalbox" href="#inline"><img alt="" src="pencil.png" /></asp:LinkButton>
           
           
          <div id="inline">
              <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
             <ContentTemplate> 
          <table>
           <tr><td>Name</td><td>
               <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("p_name") %>'></asp:TextBox></td></tr>
             <tr><td>Address</td><td>
               <asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("p_address") %>'></asp:TextBox></td></tr>
             <tr><td>
                 </td><td>
                 
                 <asp:Button ID="Button1" runat="server" Text="Update" CommandName="Edit" CommandArgument='<%#Eval("p_id") %>'/></td></tr>
                 <tr>
                 <br />
              <asp:UpdateProgress ID="UpdateProgress1" runat="server">
              <ProgressTemplate>
              <%--<img src="ajaxgif.gif" />--%>
              Updating...
              
              </ProgressTemplate>
              </asp:UpdateProgress>
                        <tr><asp:Label ID="Label1" runat="server"></asp:Label></tr>

              </tr>
              
          </table>
          </ContentTemplate>
          </asp:UpdatePanel>
          </div>
          
          
           
           </td></tr>
        
        </ItemTemplate>
        <FooterTemplate>
        
         </table>
        
        </FooterTemplate>
        
        
        
        </asp:Repeater>
Posted
Comments
Deenuji 5-Dec-12 4:59am    
u can see that label before update?????
Surendra0x2 5-Dec-12 5:03am    
Yes i tested it is showing before updation means if i set Text="Something" then it is showing But when i'm clicking on Update Button then it is not showing

C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
   Thread.Sleep(3000);        
   TextBox name = (TextBox)e.Item.FindControl("TextBox1");
   TextBox address = (TextBox)e.Item.FindControl("TextBox2");
   Label lbl = (Label)e.Item.FindControl("Label1"); 
   if (e.CommandName == "Edit")
   {
      int p_id = Convert.ToInt32(e.CommandArgument);
      SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
                SqlCommand sqlcomm = new SqlCommand("Update persons set p_name='" +name.Text +"' , p_address='" + address.Text + "'  where p_id='" + p_id + "'", sqlconn);
      sqlconn.Open();
      sqlcomm.ExecuteNonQuery();
      sqlconn.Close();
      lbl.Text = "Updated";       
   }                             
}

//Don't Call Your Bind() Method In ItemCommand Event and Call it In Your Page_Load With IspostBack=false
//In Page_Load
If(!IsPostBack)
{
   Bind();//Use it!....
}          
 
Share this answer
 
v2
Comments
Surendra0x2 5-Dec-12 6:03am    
Thank You SO Much Buddy U soved My Problem yaar i Removed Bind() Method From itemcommand
and did
Label lbl = (Label)e.Item.FindControl("Label1");
lbl.Text = "Updated";
then it worked but when i'm just writing Label1.Text="Updated" then was not showing

anyways thanks i manipulated the code and it worked thanks
RahulRana723 5-Dec-12 6:08am    
Label1.Text is also working fine but it show updated msg on secondlast record.you must find its Id According To Its Items Id.Use Firefox Bug for Clearing it.Ok Surendra
Surendra0x2 5-Dec-12 6:11am    
Ok :)
Surendra0x2 5-Dec-12 6:30am    
Buddy But there is one problem arised when i'm clicking on any edit Button then it is only showing first record in pop-up it is only showing first row's Record in each row pop-up :(
RahulRana723 5-Dec-12 6:41am    
Show Me Your Entire Code.then I fix its errors
Hi,

You have placed Label1 Outside of the update panel and the event is raised from inside the update panel. So the label's text is changed but it is not refreshed on the client side.

So the solution is You have to put the label inside the update panel.

Also one more suggestion, instead of putting update panel inside ItemTemplate, put the Repeater control itself inside the update panel.
Having lots of update panels in a page is also not a good practice.


Hope this helps you.

-Gayatri
 
Share this answer
 
Comments
Surendra0x2 5-Dec-12 6:10am    
Mam My Label is Inside Update Panel.
and i'm Opening the Content which i palced Inside Update panel in Fancybox so i dnt wanna refresh the page thats y i'm using update panel.

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