locked
image cannot display in gridview on button click if statement? RRS feed

  • Question

  • User-1647172364 posted
    hello sir i want to insert image through the file upload option here i use if else on button click else part is working if part is
    not working the image cant show in gridview

    here is my code
    please execute them cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.IO; namespace WebApplication14 { public partial class Test_lang : System.Web.UI.Page { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); string connection = System.Configuration.ConfigurationManager.AppSettings["con"].ToString(); public void EstablishConnection(string storeprocedure) { con.ConnectionString = connection; cmd.Connection = con; cmd.Connection.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = storeprocedure; } public void CloseConnection() { cmd.Connection.Close(); cmd.Connection.Dispose(); con.Close(); } public void FillGridview() { SqlDataAdapter adp = new SqlDataAdapter("select * from test_lang", connection); adp.SelectCommand.CommandType = CommandType.Text; DataTable DT = new DataTable(); adp.Fill(DT); Gv1.DataSource = DT; Gv1.DataBind(); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { FillGridview(); BT_update.Visible = false; } } protected void BT_submit_Click(object sender, EventArgs e) { //string filename = Path.GetFileName(fileupload.PostedFile.FileName); //fileupload.SaveAs(Server.MapPath("~/img/" + filename)); if (fileupload.HasFiles) { try { BT_submit.Text = "Subt"; string fileName = Path.GetFileName(fileupload.PostedFile.FileName); string filePath = "~/img/" + fileName; fileupload.PostedFile.SaveAs(Server.MapPath(filePath)); EstablishConnection("sp_insert_test_lang"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString(); cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString(); cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = filePath; FillGridview(); } catch (Exception ex) { BT_submit.Text = ex.Message; } //try { cmd.ExecuteNonQuery(); } //catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } } else { EstablishConnection("sp_insert_test_lang1"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString(); cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString(); cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = "null"; FillGridview(); CloseConnection(); try { cmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } } } protected void BT_update_Click(object sender, EventArgs e) { //string fileName = Path.GetFileName(fileupload.PostedFile.FileName); //string filePath = "~/img/" + fileName; //fileupload.PostedFile.SaveAs(Server.MapPath(filePath)); EstablishConnection("sp_update_test_lang"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; //cmd.Parameters.Add("@image", SqlDbType.VarChar, 255).Value = filePath; cmd.Parameters.Add("@tbl_id", SqlDbType.VarChar, 100).Value = HiddenField1.Value; try { cmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } CloseConnection(); FillGridview(); Response.Redirect(Request.Url.AbsoluteUri); } protected void Gv1_PageIndexChanging(object sender, GridViewPageEventArgs e) { Gv1.PageIndex = e.NewPageIndex; FillGridview(); } protected void Button1_Click(object sender, EventArgs e) { LinkButton btn = (LinkButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; tb_name.Text = gvr.Cells[0].Text; tb_last.Text = gvr.Cells[1].Text; HiddenField1.Value = Gv1.DataKeys[gvr.RowIndex].Values[0].ToString(); BT_update.Visible = true; BT_submit.Visible = false; } } } aspx <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Test lang.aspx.cs" Inherits="WebApplication14.Test_lang" %> <asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server"> <div style="margin-top:30px; margin-left:20px"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:HiddenField ID="HiddenField1" runat="server" /> <h1><strong style="color:black">Test Language</strong></h1> <hr /> <table> <tr> <td><span style="color:black">First Name</span><br /> <asp:TextBox ID ="tb_name" runat="server" Width="200px" /><br /> </td> <td><span style="margin-left:25px; color:black">Last Name<br /></span> <span style="margin-left:25px"><asp:TextBox ID="tb_last" runat="server" Width="200px" /></span> <br /> </td></tr> <tr> <td> <br /><asp:FileUpload ID="fileupload" runat="server" BackColor="lightblue" /> </td> </tr> <tr> <td><br /> <asp:Button ID="BT_submit" runat="server" Text="Submit" style="border-radius:5px" Height="35px" Width="80px" OnClick="BT_submit_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /> <asp:Button ID="BT_update" runat="server" Text="Update" style="border-radius:5px" Height="35px" Width="80px" OnClick="BT_update_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /> </td> </tr> </table> <br /><asp:GridView runat="server" AutoGenerateColumns="false" ID="Gv1" Width="60%" OnPageIndexChanging="Gv1_PageIndexChanging" AllowPaging="true" PageSize="10" DataKeyNames="tbl_id"> <Columns> <asp:BoundField DataField ="first_name" HeaderText ="First Name" ItemStyle-HorizontalAlign="Center" /> <asp:BoundField DataField ="last_Name" HeaderText ="Last Name" /> <asp:ImageField DataImageUrlField="image" HeaderText="Image" ControlStyle-Height="95" ControlStyle-Width="170" ItemStyle-HorizontalAlign="Center"> </asp:ImageField> <%--<asp:TemplateField> <ItemTemplate> <asp:Image runat="server" ID="img1" ImageUrl='<%# Eval("Image")%>' Width="100" Height="100" /> </ItemTemplate> </asp:TemplateField> --%> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="Button1" runat="server" Text="Edit" OnClick="Button1_Click" ></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView> </ContentTemplate></asp:UpdatePanel> </div> </asp:Content>

    Wednesday, July 1, 2020 10:36 AM

Answers

  • User-939850651 posted

    Hi sanam13,

    sanam13

    if (fileupload.HasFiles)
                {
                    try
                    {
                        BT_submit.Text = "Subt";
                        string fileName = Path.GetFileName(fileupload.PostedFile.FileName);
                        string filePath = "~/img/" + fileName;
    
                        fileupload.PostedFile.SaveAs(Server.MapPath(filePath));
    
                        EstablishConnection("sp_insert_test_lang");
                        cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text;
                        cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text;
                        cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1";
                        cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString();
                        cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1";
                        cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString();
                        cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = filePath;
                        FillGridview();
                    }
                    catch (Exception ex)
                    {
                        BT_submit.Text = ex.Message;
                    }
                    //try { cmd.ExecuteNonQuery(); }
                    //catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }
                }
                else
                {
                ......
                }

    In the part of the code you marked in yellow, I only saw adding parameters and setting the command type to a stored procedure, but did not execute it.

    So it will not insert records into the database.

    On the other hand, you need to rebind the data source of gridview after executing this command.

    Just like this:

    if (fileupload.HasFiles)
    {
    try
    {
    BT_submit.Text = "Subt";
    //upload the image file to server path
    string fileName = Path.GetFileName(fileupload.PostedFile.FileName);
    string filePath = "~/img/" + fileName;
    fileupload.PostedFile.SaveAs(Server.MapPath(filePath));
    //set command type and paramters
    EstablishConnection("sp_insert_test_lang");
    cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text;
    cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text;
    cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1";
    cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString();
    cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1";
    cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString();
    cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = filePath;
    // excute the command
    cmd.ExecuteNonQuery();
    //rebind the data source of gridview
    FillGridview();
    }
    catch (Exception ex)
    {
    BT_submit.Text = ex.Message;
    }
    }
    else {
    ......
    }

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 2, 2020 2:23 AM

All replies

  • User-939850651 posted

    Hi sanam13,

    sanam13

    if (fileupload.HasFiles)
                {
                    try
                    {
                        BT_submit.Text = "Subt";
                        string fileName = Path.GetFileName(fileupload.PostedFile.FileName);
                        string filePath = "~/img/" + fileName;
    
                        fileupload.PostedFile.SaveAs(Server.MapPath(filePath));
    
                        EstablishConnection("sp_insert_test_lang");
                        cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text;
                        cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text;
                        cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1";
                        cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString();
                        cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1";
                        cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString();
                        cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = filePath;
                        FillGridview();
                    }
                    catch (Exception ex)
                    {
                        BT_submit.Text = ex.Message;
                    }
                    //try { cmd.ExecuteNonQuery(); }
                    //catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }
                }
                else
                {
                ......
                }

    In the part of the code you marked in yellow, I only saw adding parameters and setting the command type to a stored procedure, but did not execute it.

    So it will not insert records into the database.

    On the other hand, you need to rebind the data source of gridview after executing this command.

    Just like this:

    if (fileupload.HasFiles)
    {
    try
    {
    BT_submit.Text = "Subt";
    //upload the image file to server path
    string fileName = Path.GetFileName(fileupload.PostedFile.FileName);
    string filePath = "~/img/" + fileName;
    fileupload.PostedFile.SaveAs(Server.MapPath(filePath));
    //set command type and paramters
    EstablishConnection("sp_insert_test_lang");
    cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text;
    cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text;
    cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1";
    cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString();
    cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1";
    cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString();
    cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = filePath;
    // excute the command
    cmd.ExecuteNonQuery();
    //rebind the data source of gridview
    FillGridview();
    }
    catch (Exception ex)
    {
    BT_submit.Text = ex.Message;
    }
    }
    else {
    ......
    }

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 2, 2020 2:23 AM
  • User-1647172364 posted
    Hlo Sir

    Insertion Operation is running successfully but when click on edit link button image path not fill to source fileupload option.
    As other two textbox updating successfully i also want to update image also through click on edit link button.

    Here is my code

    Please execute it.

    Aspx <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Test lang.aspx.cs" Inherits="WebApplication14.Test_lang" %> <asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server"> <div style="margin-top:30px; margin-left:20px"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:HiddenField ID="HiddenField1" runat="server" /> <h1><strong style="color:black">Test Language</strong></h1> <hr /> <table> <tr> <td><span style="color:black">First Name</span><br /> <asp:TextBox ID ="tb_name" runat="server" Width="200px" /><br /> </td> <td><span style="margin-left:25px; color:black">Last Name<br /></span> <span style="margin-left:25px"><asp:TextBox ID="tb_last" runat="server" Width="200px" /></span> <br /> </td></tr> <tr> <td> <br /><asp:FileUpload ID="fileupload" runat="server" BackColor="lightblue" /> </td> </tr> <tr> <td><br /> <asp:Button ID="BT_submit" runat="server" Text="Submit" style="border-radius:5px" Height="35px" Width="80px" OnClick="BT_submit_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /> <asp:Button ID="BT_update" runat="server" Text="Update" style="border-radius:5px" Height="35px" Width="80px" OnClick="BT_update_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /> </td> </tr> </table> <br /><asp:GridView runat="server" AutoGenerateColumns="false" ID="Gv1" Width="60%" OnPageIndexChanging="Gv1_PageIndexChanging" AllowPaging="true" PageSize="10" DataKeyNames="tbl_id"> <Columns> <asp:BoundField DataField ="first_name" HeaderText ="First Name" ItemStyle-HorizontalAlign="Center" /> <asp:BoundField DataField ="last_Name" HeaderText ="Last Name" /> <asp:ImageField DataImageUrlField="image" HeaderText="Image" ControlStyle-Height="95" ControlStyle-Width="170" ItemStyle-HorizontalAlign="Center"> </asp:ImageField> <%-- <asp:TemplateField> <ItemTemplate> <asp:Image runat="server" ID="img1" ImageUrl='<%# Eval("Image")%>' Width="100" Height="100" /> </ItemTemplate> </asp:TemplateField> --%> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="Button1" runat="server" Text="Edit" OnClick="Button1_Click" ></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView> </ContentTemplate></asp:UpdatePanel> </div> </asp:Content> Cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.IO; using System.Configuration; namespace WebApplication14 { public partial class Test_lang : System.Web.UI.Page { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); string connection = System.Configuration.ConfigurationManager.AppSettings["con"].ToString(); public void EstablishConnection(string storeprocedure) { con.ConnectionString = connection; cmd.Connection = con; cmd.Connection.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = storeprocedure; } public void CloseConnection() { cmd.Connection.Close(); cmd.Connection.Dispose(); con.Close(); } public void FillGridview() { SqlDataAdapter adp = new SqlDataAdapter("select * from test_lang", connection); adp.SelectCommand.CommandType = CommandType.Text; DataTable DT = new DataTable(); adp.Fill(DT); Gv1.DataSource = DT; Gv1.DataBind(); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { FillGridview(); BT_update.Visible = false; } } protected void BT_submit_Click(object sender, EventArgs e) { //string filename = Path.GetFileName(fileupload.PostedFile.FileName); //fileupload.SaveAs(Server.MapPath("~/img/" + filename)); if (fileupload.HasFiles) { string fileName = Path.GetFileName(fileupload.PostedFile.FileName); string filePath = "~/img/" + fileName; fileupload.PostedFile.SaveAs(Server.MapPath(filePath)); EstablishConnection("sp_insert_test_lang"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString(); cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString(); cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = filePath; FillGridview(); try { cmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } CloseConnection(); Response.Redirect(Request.Url.AbsoluteUri); } else { EstablishConnection("sp_insert_test_lang"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString(); cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString(); cmd.Parameters.Add("@image", SqlDbType.NVarChar, 255).Value = "null"; FillGridview(); try { cmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } CloseConnection(); Response.Redirect(Request.Url.AbsoluteUri); } } protected void BT_update_Click(object sender, EventArgs e) { //if (fileupload.HasFiles) //{ string fileName = Path.GetFileName(fileupload.PostedFile.FileName); string filePath = "~/img/" + fileName; fileupload.PostedFile.SaveAs(Server.MapPath(filePath)); EstablishConnection("sp_update_test_lang"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; cmd.Parameters.Add("@image", SqlDbType.VarChar, 255).Value = filePath; cmd.Parameters.Add("@tbl_id", SqlDbType.VarChar, 100).Value = HiddenField1.Value; try { cmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } CloseConnection(); FillGridview(); Response.Redirect(Request.Url.AbsoluteUri); //} //else //{ // EstablishConnection("sp_insert_test_lang"); // cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; // cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; // cmd.Parameters.Add("@image", SqlDbType.VarChar, 255).Value = "null"; // cmd.Parameters.Add("@tbl_id", SqlDbType.VarChar, 100).Value = HiddenField1.Value; // FillGridview(); // try { cmd.ExecuteNonQuery(); } // catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } // CloseConnection(); // Response.Redirect(Request.Url.AbsoluteUri); //} } protected void Gv1_PageIndexChanging(object sender, GridViewPageEventArgs e) { Gv1.PageIndex = e.NewPageIndex; FillGridview(); } protected void Button1_Click(object sender, EventArgs e) { LinkButton btn = (LinkButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; tb_name.Text = gvr.Cells[0].Text; tb_last.Text = gvr.Cells[1].Text; HiddenField1.Value = Gv1.DataKeys[gvr.RowIndex].Values[0].ToString(); BT_update.Visible = true; BT_submit.Visible = false; } } }

    Thursday, July 2, 2020 8:45 AM