asp.net mvc 3 - how to dynamically edit the bind data in sql using mvc3 web grid -


i new mvc.. have task that, have bind data existing table in sql using asp.net mvc3(razor) web grid .. have edit data in webgrid.. dont know how edit operation going made... plzz me out...

i have given bind data.. plz let me know how edit it...

controller:

    public actionresult index()     {         var list = getlist();         return view(list);      }      public list<teacher> getlist()     {         var modellist = new list<teacher>();         using (sqlconnection conn = new sqlconnection(@"integrated security=sspi;persist security info=false;initial catalog=demo;data source=cipl41\sqlexpress"))         {             conn.open();             sqlcommand dcmd = new sqlcommand("select t_id,t_name,t_address,sub_id teacher", conn);             sqldataadapter da = new sqldataadapter(dcmd);             dataset ds = new dataset();             da.fill(ds);             conn.close();             (int = 0; <= ds.tables[0].rows.count - 1; i++)             {                 var model = new teacher();                 model.t_id = convert.toint32(ds.tables[0].rows[i]["t_id"]);                 model.t_name = ds.tables[0].rows[i]["t_name"].tostring();                 model.t_address = ds.tables[0].rows[i]["t_address"].tostring();                 model.sub_id = ds.tables[0].rows[i]["sub_id"].tostring();                 modellist.add(model);             }         }         return modellist;     }     // 

index.cshtml

    @model ienumerable<mvcapplication1.models.teacher>      @{       viewbag.title = "index";       }      <h2>index</h2>     @using (html.beginform("index", "teacher"))        {       <table> <tr>     <th></th>     <th>         t_id     </th>     <th>         t_name     </th>     <th>         t_address     </th>     <th>         sub_id     </th>  </tr>   @foreach (var item in model)  {  <tr>     <td>         @html.actionlink("edit", "edit", new { id=item.t_id }) |        @* @html.actionlink("details", "details", new { id=item.t_id }) |*@         @html.actionlink("delete", "delete", new {  id=item.t_id })     </td>     <td>        @html.textbox("t_id",  item.t_id , new { @style = "width:100px;" })     </td>     <td>         @html.textbox("t_name",  item.t_name , new { @style = "width:100px;" })          </td>     <td>         @html.textbox("t_address",  item.t_address , new { @style = "width:100px;" })      </td>     <td>         @html.textbox("sub_id",item.sub_id,new { @style = "width:100px;"})     </td>  </tr>   }     </table> 

plz me out....

have @ tutorial http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/examining-the-edit-methods-and-edit-view

i think explains you're trying do.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -