Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 06, 2012 09:11 AM by superguppie
Aug 03, 2012 07:52 PM|LINK
My client requirement is - In a gridview there is a dropdown called "Rule".Now there is a Add button outside grid.On click of add button gridview generates one more row.I need to calculate total row number and take module(%2) with precision value(if row
no is 5 the 5%2=2) to get the Rule value and need to bind it with dropdown.
that means: initially grid has 1 row and Rule ddlist has value 1. Now on adding 1 more row grid row count becomes 2
now grid has 2 row and Rule ddlist will have value 1
like wise when grid will have 4 rows then Rule ddlist should have 1,2 (because 4%2=2) for 6 rows value should have 1,2,3.
I need help or some code snippet.
Aug 04, 2012 05:15 AM|LINK
Please try this
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
int index = e.Row.RowIndex;
int count = index / 2;
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
for (int i = 0; i < count; ++i)
Please mark this post as Answer if this helped you.
Aug 06, 2012 09:11 AM|LINK
Hmmmmm, you seem to need the result of integer division, not the remainder of integer division. (Modulo is the remainder of integer division. 5 % 2 = 1. 4 % 2 = 0.)
Have you succeeded in adding a Row? If so, how did you do it?
Typically, it is done using a DataBind each time a new Row is done. Since you need the total number of Rows, I think you had best use the DataBound event. In the handler, loop over the Rows collection. Find the DropDownList in each Row, and DataBind it.