i want add one more column to grid and bind that data and display by using datarowbound event
About rowdatabound
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
i want add one more column to grid and bind that data and display by using datarowbound event
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lokesh VarmanRank #374 · 6.8K reputationPosted Jul 23, 2023, 9:15 AM EDT
To add one more column to a grid and bind the data in the
DataRowBoundevent using ASP.NET Web Forms,In your ASPX page, open the markup and add a new
orto the GridView. For demonstration purposes, let's assume you want to add a column for displaying the "Status" of each row. You can use ato achieve this.In your code-behind file (C#), bind the data to the GridView. You can do this during the Page_Load event or any other appropriate event.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Assuming you have a DataTable named "dataTable" with data to bind to the GridView GridView1.DataSource = dataTable; GridView1.DataBind(); } }In the
DataRowBoundevent, you can access the newly added column and set its value based on the data in the corresponding row.protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Access the Label control in the "Status" column Label lblStatus = (Label)e.Row.FindControl("LblStatus"); // Assuming the "Status" information is available in the "Status" column of your data source DataRowView rowView = (DataRowView)e.Row.DataItem; string status = rowView["Status"].ToString(); // Set the value of the Label control to the "Status" value lblStatus.Text = status; } }