In my gridview which is in update mode, I need to increment a column value.
Ex: In my gridview have 5 rows and three columns. I need to increment the serial number column value by 1. Increment Gridview1.Rows[1].Cells[2] value by 1 up to 5th row. But when I execute the code it will result the output put of all the column same. This is my code.
{
int totalRows = GridView1.Rows.Count;
for (int RowIndex = 0; RowIndex < totalRows; RowIndex++)
{
GridViewRow row = GridView1.Rows[RowIndex];
TextBox txtslno = row.FindControl("txtslno") as TextBox;
int number = int.Parse(TextBox5.Text);
if (GridView1.Rows.Count > 1)
{
for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
txtslno.Text = (number + 1).ToString();
number++;
}
}
}
}
Imtiyaz AnsariRank #1,031 · 1.9K reputationPosted Dec 28, 2015, 11:38 PM EST
Raja TRank #685 · 3.5K reputationPosted Dec 28, 2015, 10:56 PM EST
asp:GridView ID="GridEmployee" runat="server" AutoGenerateColumns="false" CellPadding="5" Style="background-color: #f1f1f1; width: 50%;"> Columns> asp:TemplateField HeaderText="S.No"> ItemTemplate> Container.DataItemIndex+1 %> ItemTemplate> asp:TemplateField> Columns> asp:GridView>more details check out below linkImtiyaz AnsariRank #1,031 · 1.9K reputationPosted Dec 28, 2015, 11:04 PM EST
Sivajihero Hero99 reputationPosted Dec 28, 2015, 11:07 PM EST
Sivajihero Hero99 reputationPosted Dec 28, 2015, 11:08 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts