locked
Description of Id Column RRS feed

  • Question

  • User-1499457942 posted

    Hi

      In Gridview i am displaying ID of Product . I want to display the Description of that Id in Gridview . I have Edit Record as Linkbutton

    Thanks

    Thursday, August 23, 2018 11:24 AM

Answers

  • User283571144 posted

    Hi JagjitSingh,

      In Gridview i am displaying ID of Product . I want to display the Description of that Id in Gridview . I have Edit Record as Linkbutton

    According to your description, I couldn't understand your reqirement clearly.

    Do you mean you want to know hwo to show the description of the product according to product ID?

    If this is your requirement, I suggest you could directly show the description of the product id in the girdview.

    Like below:

    <!DOCTYPE html>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="gvData" runat="server">
                </asp:GridView>
            </div>
        </form>
    </body>
    </html>
    

    Code-behind:

    using System;
    using System.Data;
     
    namespace WebApplication.views
    {
        public partial class _2145855 : System.Web.UI.Page
        {
            private static DataTable source = new DataTable();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    if (source.Columns.Count == 0 && source.Rows.Count == 0)
                    {
                        source.Columns.Add(new DataColumn("ID"));
                        source.Columns.Add(new DataColumn("Description"));
     
                        for (int i = 0; i < 10; i++)
                        {
                            DataRow row = source.NewRow();
                            row["ID"] = Convert.ToString(i + 1);
                            row["Description"] = string.Format("Description{0}", i + 1);
                            source.Rows.Add(row);
                        }
                    }
                }
     
                this.gvData.DataSource = source;
                this.gvData.DataBind();
            }
        }
    }
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 26, 2018 2:43 AM