locked
Gridview Attaching documents RRS feed

  • Question

  • User581091753 posted

    my first form has a gridview in which i have a link button. The fields in this Gridview are FlimsyID, DateLogged, Initial, Comments, Email. This come from SQL Database. when the link button is clicked it goes to file upload page where i can attach documents.

    What i want to do is to get the flimsyID and store it in the second gridview for attaching documents. Is this possible

    Thanking you in advance

    The code is as follows

    Default.aspx

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="FlimsySQL._Default" %>

    <asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
        <section class="featured">
            <div class="content-wrapper">
                <hgroup class="title">
                </hgroup>
            </div>
        </section>
        <br />
    </asp:Content>
    <asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
        <br />
        <asp:LoginView ID="LoginView1" runat="server">
            <AnonymousTemplate>
                Please register or login
                <br />
                <br />
                Please note recomended browser for CMS is <b style="mso-bidi-font-weight: normal"><span style="font-size: 12.0pt; line-height: 115%; font-family: &quot;Segoe UI&quot;,&quot;sans-serif&quot;; color: #466A20">Google chrome or Firefox<br />
                <br />
                If you want to reset your password Click here</span><asp:LinkButton ID="LinkButton4" runat="server" OnClick="LinkButton4_Click" OnClientClick="~/ChangePassword.aspx">Change Password</asp:LinkButton>
                . <span style="font-size: 12.0pt; line-height: 115%; font-family: &quot;Segoe UI&quot;,&quot;sans-serif&quot;; color: #466A20">You must know your current password to reset your password<br />
                <br />
                If you dont know your password Please call IT</span></b><br />
            </AnonymousTemplate>
            <LoggedInTemplate>
                <asp:Button ID="btnAddFlimsy" runat="server" OnClick="btnAddFlimsy_Click" Text="Add Flimsy" />
            </LoggedInTemplate>
            <RoleGroups>
                <asp:RoleGroup Roles="All">
                </asp:RoleGroup>
            </RoleGroups>
        </asp:LoginView>
        <asp:FormView ID="FormView1" runat="server">
            <InsertItemTemplate>
                <br />
                <br />
                <br />
            </InsertItemTemplate>
            <ItemTemplate>
                <br />
                <br />
                <asp:TextBox ID="txtFlimsyID" runat="server" Visible="False"></asp:TextBox>
                <br />
                Flimsy ID:&nbsp;<asp:Label ID="Label9" runat="server"></asp:Label>
                <br />
                <br />
                <br />
                <asp:Label ID="lblDateLogged" runat="server"></asp:Label>
                <asp:TextBox ID="txtDateLogged" runat="server" Visible="False"></asp:TextBox>
                <br />
                <asp:Label ID="Label3" runat="server" style="font-weight: 700" Text="Initial"></asp:Label>
                <asp:Label ID="Label10" runat="server"></asp:Label>
                <br />
                <asp:TextBox ID="txtInitial" runat="server"></asp:TextBox>
                <br />
                <asp:Label ID="Label4" runat="server" style="font-weight: 700" Text="Comments"></asp:Label>
                <br />
                <asp:TextBox ID="txtComments" runat="server" Height="65px" TextMode="MultiLine" Width="339px"></asp:TextBox>
                <asp:Label ID="Label11" runat="server"></asp:Label>
                <br />
                <asp:Label ID="Label5" runat="server" style="font-weight: 700" Text="Email"></asp:Label>
                <br />
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                <asp:Label ID="Label12" runat="server"></asp:Label>
                <br />
                <br />
                <br />
                <br />
                &nbsp;<br />
                <br />
                <br />
                <asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" />
                <br />
                <br />
                <br />
                <br />
                <br />
            </ItemTemplate>
        </asp:FormView>
        <br />
        <asp:Label ID="lblUsername" runat="server" Visible="False"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="lblDateLogged" runat="server" Visible="False"></asp:Label>
        <br />
        <br />
        <br __designer:mapid="16f" />
    <br __designer:mapid="170" />
    <asp:TextBox ID="txtFlimsyID" runat="server" Visible="False"></asp:TextBox>
    <br __designer:mapid="172" />
    <br __designer:mapid="173" />
    <br __designer:mapid="174" />
    <br __designer:mapid="175" />
    <asp:Label ID="lblDateLogged0" runat="server" Visible="False"></asp:Label>
    <asp:TextBox ID="txtDateLogged" runat="server" Visible="False"></asp:TextBox>
    <br __designer:mapid="178" />
    <asp:Label ID="Label3" runat="server" style="font-weight: 700" Text="Initial" Visible="False"></asp:Label>
    <br __designer:mapid="17a" />
    <asp:TextBox ID="txtInitial" runat="server" Visible="False"></asp:TextBox>
    <br __designer:mapid="17c" />
    <asp:Label ID="Label4" runat="server" style="font-weight: 700" Text="Comments" Visible="False"></asp:Label>
    <br __designer:mapid="17e" />
    <asp:TextBox ID="txtComments" runat="server" Height="65px" TextMode="MultiLine" Width="339px" Visible="False"></asp:TextBox>
    <br __designer:mapid="180" />
    <asp:Label ID="Label5" runat="server" style="font-weight: 700" Text="Email" Visible="False"></asp:Label>
    <br __designer:mapid="182" />
    <asp:TextBox ID="txtEmail" runat="server" Visible="False"></asp:TextBox>
    <br __designer:mapid="184" />
    <br __designer:mapid="185" />
    <br __designer:mapid="186" />
    <br __designer:mapid="187" />&nbsp;<br __designer:mapid="18a" />
    <asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" Visible="False" />
    <br __designer:mapid="18c" />
    <br __designer:mapid="18d" />
        <asp:GridView ID="GVFlimsy" runat="server" OnSelectedIndexChanged = "OnSelectedIndexChanged" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="FlimsyId" DataSourceID="SqlDataSource1" AllowSorting="True" Visible="False">
            <Columns>
                <asp:TemplateField>
                    <EditItemTemplate>
                        <br />
                        <br />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label6" runat="server"></asp:Label>
                        <br />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton3" runat="server" PostBackUrl="~/Attach/Uploads.aspx" OnClick="LinkButton3_Click">LinkButton</asp:LinkButton>
                        <asp:Label ID="Label14" runat="server" Text='<%# Eval("FlimsyId") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton4" runat="server" PostBackUrl="~/Attach/Uploads.aspx" OnClick="LinkButton4_Click1"></asp:LinkButton>
                        <asp:Label ID="Label13" runat="server" Text='<%# Eval("FlimsyId") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="FlimsyId" InsertVisible="False" SortExpression="FlimsyId">
                    <EditItemTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%# Eval("FlimsyId") %>'></asp:Label>
                        <br />
                        <br />
                        <br />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblflimsyID" runat="server" Text='<%# Bind("FlimsyId") %>'></asp:Label>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FlimsyId") %>' Visible="False"></asp:TextBox>
                        <br />
                        <br />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="DateLogged" SortExpression="DateLogged">
                    <EditItemTemplate>
                        <asp:TextBox ID="DateLogged1TextBox" runat="server" Text='<%# Bind("DateLogged") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("DateLogged") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Initial" HeaderText="Initial" SortExpression="Initial" />
                <asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            </Columns>
        </asp:GridView>
    <br __designer:mapid="18f" />
    <br __designer:mapid="190" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TLTBFlimsyConnectionString %>" SelectCommand="SELECT * FROM [Flimsy]"  UpdateCommand="UPDATE [Flimsy] set [DateLogged]=@DateLogged,[Initial]=@Initial,[Email]=@Email where [FlimsyID]=@FlimsyID " DeleteCommand="DELETE from [Flimsy] where [FlimsyID]=@FlimsyID">
            <DeleteParameters>
                <asp:Parameter Name="FlimsyID" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="DateLogged" />
                <asp:Parameter Name="Initial" />
                <asp:Parameter Name="Email" />
                <asp:Parameter Name="FlimsyID" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <br />
        <br />
        <asp:TextBox ID="txtUsername1" runat="server" Visible="False"></asp:TextBox>
        <br />
        <br />
        <br />
        <br />
        </asp:Content>

    Default.aspx.cs

    using System;

    using System.Data;

    using System.Configuration;
    using System.Collections;
    using System.ComponentModel;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.SessionState;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    using System.Xml.Linq;
    using System.Globalization;
    using System.Text.RegularExpressions;
    using System.IO;



    namespace FlimsySQL
    {
        public partial class _Default : Page
        {
            SqlConnection con = new SqlConnection(@"Data Source=TLTB-SA-LPT\SQL2015;Initial Catalog=TLTBFlimsy;Integrated Security = true");

            
            protected void Page_Load(object sender, EventArgs e)
        {

                
                
                txtUsername1.Text = User.Identity.Name.ToString();
        
             lblUsername.Visible = false;
            lblDateLogged.Visible = false;

            lblUsername.Text = "Username: " + User.Identity.Name.ToString();
            lblDateLogged.Text = "Date Logged: " + DateTime.Now.ToShortDateString();



            //TextBox DateLoggedTextBox1 = GVFlimsy.FindControl("DateLoggedTextBox") as TextBox;
          //DateLoggedTextBox1.Text = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
            //lblDateLogged.Text = "Date Logged: " + DateTime.Now.ToShortDateString();
           // txtFlimsyID.Text = (FindControl("label7") as Label).Text;
               // Label9.Text = "Flimsy ID: " + txtFlimsyID.Text;
            //lblflimsyid.Text=
            //Label lblflimsyid;
            //
            /*foreach (GridViewRow row in GVFlimsy.Rows)
            {
                // Selects the text from the TextBox
                // which is inside the GridView control
                string textBoxText = ((TextBox)row.FindControl("TextBox1")).Text;
                Response.Write(textBoxText);
                
                txtFlimsyID.Text = textBoxText;
                //lblflimsyid = textBoxText + 1;
            }*/
            
            //GVFlimsy.DataBind();
        }



        
          
            

            protected void Upload(object sender, EventArgs e)
            {
                
            }

            protected void btnInsert_Click(object sender, EventArgs e)
            {
               /* TextBox txtDateLogged = FormView1.FindControl("txtDateLogged") as TextBox;
                TextBox txtInitial = FormView1.FindControl("txtInitial") as TextBox;
                TextBox txtComments = FormView1.FindControl("txtComments") as TextBox;
                TextBox txtEmail = FormView1.FindControl("txtEmail") as TextBox;
                */
                
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into [Flimsy] values('" + txtDateLogged.Text + "','" + txtInitial.Text + "','" + txtComments.Text + "','" + txtEmail.Text + "')";

                cmd.ExecuteNonQuery();

                con.Close();
                Response.Redirect("default.aspx");

            

               /* TextBox UsernameTextBox = GVFlimsy.FindControl("UsernameTextBox") as TextBox;
                UsernameTextBox.Text = User.Identity.Name.ToString();
                int i = 0;
                for (i = 0; i <= GvSchedule.Rows.Count - 1; i++)
                {
                    txtFlimsyID.Text = (TextBox)GVFlimsy.Rows[i].Cells[0].FindControl("Textbox1");
                }  // Rows[i].Cells[0].FindControl("lblname");;

               */


                //lblflimsyid.text = txtFlimsyID.Text;
            }

           
            public object FlimsyID { get; set; }

            protected void txtFlimsyID_TextChanged(object sender, EventArgs e)
            {

            }

            protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
            {

            }

            protected void OnSelectedIndexChanged(object sender, EventArgs e)
            {
               GridViewRow row = GVFlimsy.SelectedRow;
                //GridView myGridview = (GridView)FormView1.Row.FindControl("GVFlimsy");
                //txtId.Text = row.Cells[0].Text;
               // txtName.Text = row.Cells[1].Text;
                //TextBox txtFlimsyID = FormView1.FindControl("txtFlimsyID") as TextBox;
                txtFlimsyID.Text = (row.FindControl("label7") as Label).Text;
            }

            protected void LinkButton3_Click(object sender, EventArgs e)
            {
                /*GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
                Label lblID = (Label)clickedRow.FindControl("label7");

                String FLimsyID = lblID.Text;// GVComplainant.DataKeys[0].Value.ToString();//GridView1.TemplateControl.FindControl("Label1") as Label;
                Session["FlimsyID"] = FLimsyID;
                Response.Redirect("~/UploadFiles/UploadFiles.aspx?ComplaintID=" + FLimsyID);
            */}

            protected void btnAddFlimsy_Click(object sender, EventArgs e)
            {
                FormView1.Visible = true;

                lblUsername.Visible = true;
                lblDateLogged.Visible = true;
                Label3.Visible = true;
                txtInitial.Visible = true;
                Label4.Visible = true;
                txtComments.Visible = true;
                Label5.Visible = true;
                txtEmail.Visible = true;
                btnInsert.Visible = true;
                lblUsername.Text = "Username: " + User.Identity.Name.ToString();
                lblDateLogged.Text = "Date Logged: " + DateTime.Now.ToShortDateString();
                GVFlimsy.Visible = true;
            }

            protected void LinkButton4_Click(object sender, EventArgs e)
            {

            }

            protected void Button1_Click(object sender, EventArgs e)
            {
               
            }

            protected void LinkButton4_Click1(object sender, EventArgs e)
            {
                GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
                Label lblFlimsyID = (Label)clickedRow.FindControl("lblFlimsyId");
               // txtFlimsyID.Text = (row.FindControl("label7") as Label).Text;
                String FlimsyID = lblFlimsyID.Text;// GVComplainant.DataKeys[0].Value.ToString();//GridView1.TemplateControl.FindControl("Label1") as Label;
                Session["FlimsyID"] = FlimsyID;
                Response.Redirect("~/Attach/Uploads.aspx?FlimsyID=" + FlimsyID);
            }

            

           
        }
    }

    Uploads.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Uploads.aspx.cs" Inherits="FlimsySQL.Attach.Uploads" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Upload" />
            <br />
            <br />
            FlimsyID:
            <asp:TextBox ID="txtFlimsyID1" runat="server"></asp:TextBox>
            <br />
            <br />
            <br />
            <asp:GridView ID="GridView1" runat="server">
                <Columns>
                    <asp:TemplateField HeaderText="FlimsyID" SortExpression="FlimsyID">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FlimsyID") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("FlimsyID") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <br />
            <br />
            <br />
        
        </div>
        </form>
    </body>
    </html>

    Uploads.aspx.cs

    using System;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;

    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;

    namespace FlimsySQL.Attach
    {
        public partial class Uploads : System.Web.UI.Page
        {

            SqlConnection con = new SqlConnection(@"Data Source=TLTB-SA-LPT\SQL2015;Initial Catalog=TLTBFlimsy;Integrated Security = true");
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindGrid();
                }
            }

             private void BindGrid()
            {
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                //Int64 FlimsyID = Convert.ToInt64(Request.QueryString["FlimsyID"].ToString());
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "select Id, Name from tblFiles ";
                        cmd.Connection = con;
                        con.Open();
                        GridView1.DataSource = cmd.ExecuteReader();
                        GridView1.DataBind();
                        con.Close();
                    }
                }
            }

            protected void DownloadFile(object sender, EventArgs e)
            {
                int id = int.Parse((sender as LinkButton).CommandArgument);
                byte[] bytes;
                string fileName, contentType;
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "select Name, Data, ContentType from tblFiles where Id=@Id";
                        cmd.Parameters.AddWithValue("@Id", id);
                        cmd.Connection = con;
                        con.Open();
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            sdr.Read();
                            bytes = (byte[])sdr["Data"];
                            contentType = sdr["ContentType"].ToString();
                            fileName = sdr["Name"].ToString();
                        }
                        con.Close();
                    }
                }
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = contentType;
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }

            protected void Button1_Click1(object sender, EventArgs e)
            {
                
                
                 string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
                string contentType = FileUpload1.PostedFile.ContentType;
                using (Stream fs = FileUpload1.PostedFile.InputStream)
                {
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        byte[] bytes = br.ReadBytes((Int32)fs.Length);
                        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                        using (SqlConnection con = new SqlConnection(constr))
                        {
                            string query = "insert into tblFiles values (@Name, @ContentType, @Data)";
                            using (SqlCommand cmd = new SqlCommand(query))
                            {
                                cmd.Connection = con;
                                cmd.Parameters.AddWithValue("@Name", filename);
                                cmd.Parameters.AddWithValue("@ContentType", contentType);
                                cmd.Parameters.AddWithValue("@Data", bytes);
                                con.Open();
                                cmd.ExecuteNonQuery();
                                con.Close();
                            }
                        }
                    }
                }
                Response.Redirect(Request.Url.AbsoluteUri);


                



            }


           
        }


        }

    Wednesday, June 22, 2016 9:48 PM

Answers

  • User1559292362 posted

    Hi ritesh2015,

    ritesh2015

    my first form has a gridview in which i have a link button. The fields in this Gridview are FlimsyID, DateLogged, Initial, Comments, Email. This come from SQL Database. when the link button is clicked it goes to file upload page where i can attach documents.

    What i want to do is to get the flimsyID and store it in the second gridview for attaching documents. Is this possible

    We could use DataKeyNames to achieve it, like this:

    <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    
        RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
    
        runat="server" AutoGenerateColumns="false">
    
        <Columns>
    
            <asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
    
            <asp:TemplateField>
    
                <ItemTemplate>
    
                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
    
                </ItemTemplate>
    
            </asp:TemplateField>
    
            <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
    
            <asp:TemplateField>
    
                <ItemTemplate>
    
                    <asp:LinkButton ID="lnkDetails" runat="server" Text="Send Details" PostBackUrl='<%# "~/Uploads.aspx?FlimsyId=" + Container.DataItemIndex %>'></asp:LinkButton>
    
                </ItemTemplate>
    
            </asp:TemplateField>
    
        </Columns>
    
    </asp:GridView>

    Fetching the GridView Row Cell Values on Next Page (Uploads Code Behind ).

    protected void Page_Load(object sender, EventArgs e)
    
    {
    
        if (this.Page.PreviousPage != null)
    
        {
    
            int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
    
            GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
    
            GridViewRow row = GridView1.Rows[rowIndex];
    
            lblId.Text = row.Cells[0].Text;
    
            lblName.Text = (row.FindControl("lblName") as Label).Text;
    
            lblCountry.Text = row.Cells[2].Text;
    
        }
    
    }

    For more information, please refer to:

    http://www.aspsnippets.com/Articles/ASPNet-Pass-or-Send-GridView-Row-Values-to-other-Page-with-HyperLink.aspx

    Best regards,

    Cole Wu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 23, 2016 8:23 AM