Hello All,
I am facing a wieard problem. I am trying to insert random values in a label inside gridview.
When I use breakpoint and debug program, It works fine and shows different-2 values in all rows. But without debugging, it shows same values in all rows.
Design:
- <asp:GridView ID="GridView1" runat="server">
- <AlternatingRowStyle Wrap="False" />
- <Columns>
- <asp:TemplateField HeaderText="StockNo">
- <ItemTemplate>
- <asp:Label ID="Label4" runat="server" Text="Label">asp:Label>
- ItemTemplate>
- asp:TemplateField>
- Columns>
- <EditRowStyle Wrap="False" />
- <EmptyDataRowStyle Wrap="False" />
- <FooterStyle Wrap="False" />
- <HeaderStyle Wrap="False" />
- <PagerStyle Wrap="False" />
- <RowStyle Wrap="False" />
- <SelectedRowStyle Wrap="False" />
- <SortedAscendingCellStyle Wrap="False" />
- <SortedAscendingHeaderStyle Wrap="False" />
- <SortedDescendingCellStyle Wrap="False" />
- <SortedDescendingHeaderStyle Wrap="False" />
- asp:GridView>
Code:
- protected void Button6_Click(object sender, System.EventArgs e)
- {
- // foreach (GridViewRow row in GridView1.Rows)
- for (int i = 0; i < GridView1.Rows.Count; i++ )
- {
- // Label lblSerial = (Label)GridView1.FindControl("Label4");
- Label txtTotal = GridView1.Rows[i].Cells[0].FindControl("Label4") as Label;
- Random random = new Random();
- string r = "";
- string N = "8988";
- string K = "";
- int j;
- for (j = 1; j < 10; j++)
- {
- r += random.Next(0, 10).ToString();
- }
- K = N + r;
- txtTotal.Text = K.ToString();
- }
- }
Please help.

Ankit ShuklaPosted May 20, 2019, 12:39 AM
Amit GuptaPosted May 18, 2019, 1:35 PM
Ankit ShuklaPosted May 18, 2019, 1:27 PM
Ankit ShuklaPosted May 18, 2019, 1:26 PM
Amit GuptaPosted May 18, 2019, 1:14 PM