TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Anji Chelloju
NA
35
12k
How to get the selected row values in asp.net mvc apllicatio
Aug 14 2013 1:57 AM
Hello every one ,
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
<script runat="server">
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();///
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div>
<form runat="server">
<div>
<div class="contant_right_top">
<h2>Delete Role</h2>
<div class="divider"></div>
<h3>Select a row to deleteā¦..</h3>
<asp:GridView ID="GridView1" CssClass ="table_font_top" runat="server"
BackColor="#D8DEE5" BorderColor="#010173"
EnableSortingAndPagingCallbacks="false" CellSpacing="2"
HorizontalAlign="Center" PageSize="5" Height="182px" Width="756px"
onselectedindexchanged="GridView1_SelectedIndexChanged1"
AutoGenerateSelectButton="True">
<AlternatingRowStyle BackColor="#F1F1F1" BorderColor="#000099"/>
</asp:GridView>
<button class="unlk_btn">Delete</button>
</div>
</div>
</div>
</form>
</asp:Content>
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("<script>alert('Role deleted Successfully')</script>");
}
else
{
Response.Write("<script>alert('Role delete failed')</script>");
}
}
return View(r);
}
Reply
Answers (
0
)
cast convert problem i want the format to be in dd/MM/yyyy
2 Modal Popup Extender controls are not working on same page