I am using asp.net mvc3.0 razor framework and html Table to bind the data with the help of ViewBag. I have to show Data as per selected option in a dropdownlist.
public ActionResult Index(GetFileName fn)
{
....
ViewBag.Grid1Data =dt;
return View();
}
At first time, I get the data but next time when another option from dropdown is selected to get second table, the ta开发者_开发知识库ble is not displayed, but I m getting the data.
View includes dropdown
<select id="Select2">
<option>Select</option>
<option>abc</option>
<option>des</option>
<option>fgh</option>
<option>next</option>
<option>first</option>
</select>
// Heading for the table
<h2>@ViewBag.Heads</h2>
// Table
<table id="table" cellpadding="10px" cellspacing="0" class="TableSty">
@for (int j = 0; j < ViewBag.Grid1Data.Rows.Count; j++)
{
var color = "";
if (j % 2 == 0)
{ color = "#f2f2f2"; }
else { color = "white"; }
<tr style="background:@color" >
@for (int c = 0; c < @ViewBag.Grid1Data.Columns.Count; c++)
{
<td class="data">@ViewBag.Grid1Data.Rows[j][c].ToString()
</td>
}
</tr>
}
</table>
Please help me out to solve the problem
Your option list and table is not bound. Best way, you use Html.DropDownListFor to render a dropdown list, so that on every selection from drop down, the page is refreshed and you get the updated data in viewbag.
Or, you have a button to submit and refresh the page manually after you select the DropDown value.
精彩评论