Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am displaying data in grid .on selecting row ,data in row should display in text boxes below it in mvc..I need help on this please its urgent ..

What I have tried:

i am able to display data in grid view
model --

public class EmpInfo
{
[DisplayName("empId")]
[Required]
[RegularExpression("([a-zA-Z0-9 .&'-]+)", ErrorMessage = "Enter only alphabets and numbers")]
public string ID { get; set; }
[DisplayName("reg Id")]
[RegularExpression("([a-zA-Z0-9 .&'-]+)", ErrorMessage = "Enter only alphabets and numbers")]

public string regid { get; set; }

[DisplayName("Number")]
public string Number { get; set; }

[DisplayName("emp Name")]
public string emp_NAME { get; set; }

[DisplayName("place ")]
public string place { get; set; }

controller --
<pre>[DisplayName("Effect Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
        public DateTime EffectDate { get; set; }
 

Controller--
 
<pre> string connectionString = ConfigurationManager.ConnectionStrings["sybaseConnect"].ConnectionString;
            string sql = string.Empty;
            AseConnection conn = new AseConnection(connectionString);
             AseCommand cmd;
            conn.Open();
            if (!(string.IsNullOrEmpty(objModel.Id)))
            {
                if (!string.IsNullOrEmpty(objModel.regId))
                {
                    sql = "select * from EMP_INFO a where ID='" + objModel.Id + "' and regID='" + objModel.regId + "'";
                }
                else
                {
 
                    sql = "select * from EMP_INFO a where ID='" + objModel.Id + "'";
                }
            }
            cmd = new AseCommand(sql, conn);
            cmd.CommandType = CommandType.Text;
            AseDataAdapter da = new AseDataAdapter();
            da.SelectCommand = cmd;
            DataSet myrec = new DataSet();
            da.Fill(myrec);
                List<empinfo> Empinfo = new List<empinfo>();
 
                DataSet ds = new DataSet();
                Connections.Connections con = new Connections.Connections();
 
                ds = con.mydata();
 
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Empinfo.Add(new empInfo
                    {
 
                        Id = dr["ID"].ToString(),
                        redId = dr["regID"].ToString(),
                        place = dr["place"].ToString(),
                        Number = dr["MCBD_ID"].ToString(),
                        NAME = dr["BANK_NAME"].ToString(),
                        
                        EffectDate = Convert.ToDateTime(dr["EMP_EFF_DT"]),
                        
                    });
                }
                return View(Empinfo);


view--
Hide   Shrink    Copy Code
@model IEnumerable<empinfogridview.models.empinfo>
 
@{
    ViewBag.Title = "empinfodata";
    var empinfodata = new WebGrid(Model, canPage: true, rowsPerPage: 5,
    selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
    empinfodata.Pager(WebGridPagerModes.NextPrevious);
}
<!DOCTYPE html>
@section featured {
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h2>@ViewBag.Message</h2>
            
        </div>
    </section>
}
@section Scripts {
 
    @Scripts.Render("~/bundles/jqueryui")
    @Styles.Render("~/Content/cssjqryUi")
    @Scripts.Render("~/jquery.validate.unobtrusive.min.js")"
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript">
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript">
 
}
 
    .webGrid {
        margin: 4px;
        border-collapse: collapse;
        width: 500px;
        background-color: #B4CFC3;
    }
 
    .header {
        background-color: #C1D4E6;
        font-weight: bold;
        color: #FFF;
    }
 
    .webGrid th, .webGrid td {
        border: 1px solid #C0C0C0;
        padding: 5px;
    }
 
    .alt {
        background-color: #E4E9F5;
        color: #000;
    }
 
    .gridHead a:hover {
        text-decoration: underline;
    }
 
    .description {
        width: auto;
    }
 
    .select {
        background-color: #71857C;
    }
    .hovercs{
             cursor: pointer;
     background-color:aquamarine;
    }
    .clickable {
        cursor: pointer;
        background: #ffff99;
    }
 

<br>
@using (Html.BeginForm("empinfodata", "EmpInfo", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    
      <pre>@Html.ValidationSummary(true)
    
        User 
        
            
                



<table class="tableSearch"><tbody><tr><td class="tdStyleForLables">
         @Html.Label("Id")
                </td><td class="tdStyleForEditor">
                    @Html.Editor("Id")
 
                </td><td class="tdStyleForLables">
                    @Html.Label("regId")
                </td><td class="tdStyleForEditor">
                    @Html.Editor("regId")
 
                </td></tr></tbody></table>
        @Html.ValidationMessage("id")<br>
        @Html.ValidationMessage("regId")
 
        <br>
 
        <br>
        
     <pre>    




Empinfodata


using (Html.BeginForm("empinfodata", "empInfo", FormMethod.Post))
{
if (ViewData["EmpData"] != null)
{
var data = (List<empinfogridview.models.empinfo>)ViewData["EmpData"];

@ViewBag.resultSetCount



@empinfodata.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: empinfodata.Columns(
empinfodata.Column("regId",format: (item) => item.GetSelectLink(item.regID.ToString())),
empinfodata.Column("Number","Number"),
empinfodata.Column("Name","name"),
empinfodata.Column("EffectDate","Effective Date"),




))



}

}
}

What I have tried:

above code is working fine with 1st requirement ..i need help on second one
Posted
Updated 17-Oct-17 3:23am
v2
Comments
Karthik_Mahalingam 16-Oct-17 23:28pm    
what kind of gird you are using?
post the code what you have tried
Use Improve question to add more info to the question.
Member 13145537 17-Oct-17 9:24am    
added my code please let me know if there are any changes to do .
Member 13145537 17-Oct-17 12:40pm    
i did get my answer ,so reposed it .

 
Share this answer
 
See the following link, it may helpful for you.

How to show data of selected row in textbox | ASP.NET Web Forms | Syncfusion[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900