Hello All
I Need to bind gridview template label filed in the loop i am getting list
My Grid view UI code :
code logic for Gridview :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//foreach (GridViewRow gvrow in GridView1.Rows)
//{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label name = (Label)e.Row.Cells[2].FindControl("lblemailtext");
for (int j = 0; j < dataTable.Rows.Count; j++)
{
//while (count >= 0)
//{
// Label name = (Label)GridView1.Rows[countnew].Cells[2].FindControl("lblemailtext");
//foreach (GridViewRow gvrow in GridView1.Rows)
//{
//Label lblEmail = (Label)gvrow.FindControl("lblemailtext");
TableCell cellnetid = e.Row.Cells[3];
BWusername = cellnetid.Text;
TableCell cell = e.Row.Cells[5];
int index = cell.Text.IndexOf('(');
if (index >= 0)
{
cell.Text = cell.Text.Substring(0, index);
}
lssEmailId.Add(dataTable.Rows[j]["NetID"] + "@****.com");
}
}
}
Naimish MakwanaPosted Apr 14, 2023, 9:49 AM
It seems like you want to bind the email value to the
lblemailtextlabel inside theGridViewusing theListlssEmailId. You can achieve this by getting the index of the current row usinge.Row.RowIndexand then using that index to get the email value from thelssEmailIdlist.Here's an updated version of your
GridView1_RowDataBoundmethod with the changesNote that you need to make sure that the
ListlssEmailIdhas the same number of items as the number of rows in theGridView, otherwise, you will get an index out of range exception.Tuhin PaulPosted Apr 16, 2023, 1:30 AM
we are accessing the label lblemailtext using FindControl and setting its Text property to the value of the corresponding item in the lssEmailId list using the RowIndex property of the current row.
Tuhin PaulPosted Apr 16, 2023, 1:30 AM
To set the email value from the list
lssEmailIdto the labellblemailtextin theGridView, you can modify theGridView1_RowDataBoundevent handler.