I am new to mvc ......here iam using a grid view in mvc2 application ........while selecting the value in gridview the page is automatically refershing.........putted in update panel,panel it is also not working...............so plz help me
here is my code
protected void Page_Load(object sender, EventArgs e)
{
//binding the roledet data values to gridview
GridView1.DataSource = ViewData["roledet"];
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
ViewData["roleno"] = GridView1.SelectedRow.Cells[2].ToString();///
}
Delete Role
Select a row to delete…..
BackColor="#D8DEE5" BorderColor="#010173"
EnableSortingAndPagingCallbacks="false" CellSpacing="2"
HorizontalAlign="Center" PageSize="5" Height="182px" Width="756px"
onselectedindexchanged="GridView1_SelectedIndexChanged1"
AutoGenerateSelectButton="True">
in model:
public bool deleterole(int roleno)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
roledet rd = new roledet();
var delrole = from role in dc.roledets where role.roleno == roleno select role;
foreach (var v in delrole)
{
rd.roleno = v.roleno;
dc.roledets.DeleteOnSubmit(rd);
dc.SubmitChanges();
}
return true;
}
in controller:
[HttpPost]
public ActionResult Delete(RoleClass r)
{
if (ModelState.IsValid)
{
int roleno = Convert.ToInt32(ViewData["roleno"]);
bool b = r.deleterole(roleno);
if (b == true)
{
Response.Write("");
}
else
{
Response.Write("");
}
}
return View(r);
}
Replies
Know the answer? Post it — somebody with the same question will find it here.