Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
every time i update my video, it doesnot show the video but if i just type random letter it does display everytime i update.

Gere is my gridview
C#
<asp:GridView ID="GridView1" runat="server" CellPadding="4" Width="100%"
        AutoGenerateColumns="False" OnRowEditing="EditRow" OnRowCancelingEdit="CancelEditRow" OnRowUpdating="UpdateRow"
        DataKeyNames="Video_Number" AllowPaging="True" OnPageIndexChanging="ChangePage" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px">
        <Columns>
        
            <asp:TemplateField HeaderText="Edit">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit" />                    
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update" />
                    <asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel" CommandName="Cancel" />
                </EditItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Video Link Name">
                <ItemTemplate>
                    <%# Eval("Video_Name")%>
                </ItemTemplate>
                <EditItemTemplate>     
                    <asp:TextBox  ID="txtName" Width="770px" Height="50px" runat="server" Text='<%# Eval("Video_Name") %>'/>
                </EditItemTemplate>
            </asp:TemplateField>



        </Columns>
        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
        <HeaderStyle BackColor="#003399" Font-Bold="true" ForeColor="#CCCCFF" />
        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
        <RowStyle BackColor="White" ForeColor="#003399" />
        <SelectedRowStyle BackColor="#009999" Font-Bold="true" ForeColor="#CCFF99" />
        <SortedAscendingCellStyle BackColor="#EDF6F6" />
        <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
        <SortedDescendingCellStyle BackColor="#D6DFDF" />
        <SortedDescendingHeaderStyle BackColor="#002876" />


    </asp:GridView>



Here is my code behind
C#
public void PopulateData()
   {
       DataTable table = new DataTable();
       using (SqlConnection conn = new SqlConnection(ConnString))
       {
           string sql = "SELECT * FROM VIDEO";
           using (SqlCommand cmd = new SqlCommand(sql, conn))
           {
               using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
               {
                   ad.Fill(table);
               }
           }
       }
       GridView1.DataSource = table;
       GridView1.DataBind();

   }

   protected void UpdateRow(object sender, GridViewUpdateEventArgs e)
   {
       var autoID = GridView1.DataKeys[e.RowIndex].Value;
       GridViewRow row = GridView1.Rows[e.RowIndex] as GridViewRow;
      TextBox tVideo= row.FindControl("txtName") as TextBox;

       //TextBox tManifesto = row.FindControl("txtManifesto") as TextBox;
       //TextBox tName = row.FindControl("txtName") as TextBox;
       //TextBox tLogo = row.FindControl("txtLogo") as TextBox;
       //DropDownList dropActive = row.FindControl("dropActive") as DropDownList;

       using (SqlConnection conn = new SqlConnection(ConnString))
       {
           //string sql = "Update PARTY set Party_Manifesto = @Party_Manifesto, " +
           //    "Party_Name = @Party_Name, Party_Logo = @Party_Logo, Status = @Status " +
           //    "WHERE Party_Number = @Party_Number";
           string sql = "Update VIDEO set Video_Name = @Video_Name WHERE Video_Number = @Video_Number";
           using (SqlCommand cmd = new SqlCommand(sql, conn))
           {

               cmd.Parameters.AddWithValue("@Video_Name", tVideo.Text.Trim());
               cmd.Parameters.AddWithValue("@Video_Number", autoID);
               conn.Open();
               cmd.ExecuteNonQuery();

               conn.Close();

           }
       }
       lblMessage.Text = "Record updated sussesfully!";
       GridView1.EditIndex = -1;
       this.PopulateData();
   }


Please help
Posted
Comments
ZurdoDev 12-Jul-13 10:39am    
What do you mean if you type a random letter it updates?
[no name] 14-Jul-13 16:58pm    
if i type "heheheheheheh" instead of the link "http://www.youtube.com/v/CXossu5pnZA" it does refresh automatically but wen i add a link it does not refresh
ZurdoDev 15-Jul-13 7:40am    
Put a breakpoint in your code and see what is happening.

1 solution

Try this,

Add event on_click in linkbutton, see below.
XML
<EditItemTemplate>
                    <asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update" onclick="lnkUpdate_click" />
                    <asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel" CommandName="Cancel" />
                </EditItemTemplate>


Then add new void in behind code

C#
protected void lnkUpdate_Click(object sender, EventArgs e)
{
var autoID = GridView1.DataKeys[e.RowIndex].Value;
        GridViewRow row = GridView1.Rows[e.RowIndex] as GridViewRow;
       TextBox tVideo= row.FindControl("txtName") as TextBox;
        

        using (SqlConnection conn = new SqlConnection(ConnString))
        {
           
            string sql = "Update VIDEO set Video_Name = @Video_Name WHERE Video_Number = @Video_Number";
            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
 
                cmd.Parameters.AddWithValue("@Video_Name", tVideo.Text.Trim());
                cmd.Parameters.AddWithValue("@Video_Number", autoID);
                conn.Open();
                cmd.ExecuteNonQuery();
 
                conn.Close();
               
            }
        }
        lblMessage.Text = "Record updated sussesfully!";
        GridView1.EditIndex = -1;
        this.PopulateData();

}



Regards,
Alexander Andri
 
Share this answer
 

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