Hello All
I Need to bind gridview template label filed in the loop i am getting list<string> , but here in the same loop i need to insert template label field to that list value. how Grid view template filed email value bind getting value from Lsstemail list item.
My Grid view UI code :
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound"> <AlternatingRowStyle BackColor="White" /> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <SortedAscendingCellStyle BackColor="#FDF5AC" /> <SortedAscendingHeaderStyle BackColor="#4D0000" /> <SortedDescendingCellStyle BackColor="#FCF6C0" /> <SortedDescendingHeaderStyle BackColor="#820000" /> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="chkAllSelect" runat="server" onclick="CheckAll(this);" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkSelect" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="chkAllSelect1" runat="server" onclick="CheckAll1(this);" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkSelect1" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:Label ID="lblemail" Text="Email" runat="server"></asp:Label> </HeaderTemplate> <ItemTemplate> <asp:Label ID="lblemailtext" runat="server"></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
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"); } } }