Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
MonthlyLeaders
ASK A QUESTION
Forumguidelines
Ankit Shukla
1.3k
668
65.3k
Problem to set values in gridview control
May 18 2019 1:08 PM
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.
Reply
Answers (
5
)
Upload File to another location
namespace or type not found