How can i get WebGrid Selected Row into Hidden Variable.
I am using the following code.
@{
var grid = new WebGrid(@ViewBag.ImageFiles, canPage: false, rowsPerPage: 5, selectionFieldName: "SelectedRow", ajaxUpdateContainerId: "gridImages");
}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
htmlAttributes: new { id = "gridImages" },
headerStyle: "header",
displayHeader: true,
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Select", format: (item) => item.GetSelectLink("Select")),
grid.Column("File", "Image")))
</div>
<input type="button" value="Submit" onclick="javascript getSelectedRow();"/>
@{
System.Dynamic.ExpandoObject expobject = null;
if (grid.HasSelection)
{
expobject = (System.Dynamic.ExpandoObject)grid.SelectedRow.Value;
<input type="hidden" id="hdnSelectedRow" name="hdnSelectedRow" value="@(expobject == null ? "" : expobject.FirstOrDefault().Value.ToString())" />
}
}
Here i am binding Datatable to Webgrid from the following code
foreach (DataRow row in imageFiles.Rows)
{
var obj = (IDictionary<string, object>)new ExpandoObject();
foreach (DataColumn col in imageFiles.Columns)
{
obj.Add(col.ColumnName, row[col.ColumnName]);
}
result.Add(obj);
}
ViewBag.ImageFiles = result;
When i click on submit button i am not getting hidden variable and value in javascript.