选择一个网格行应该在mvc中显示文本框中的行数据。我可以这样做吗? [英] Selecting a grid row should display data of row in text box in mvc.how can I do it ?

查看:61
本文介绍了选择一个网格行应该在mvc中显示文本框中的行数据。我可以这样做吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格中显示数据。在选择行时,行中的数据应显示在mvc下方的文本框中。我需要帮助,请紧急..



我尝试过:



i能够在网格视图中显示数据

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


使用(Html.BeginForm(empinfodata,empInfo,FormMethod.Post))

{

if(ViewData [EmpData]! = null)

{

var data =(List< empinfogridview.models.empinfo>)ViewData [EmpData];

@ ViewBag.resultSetCount





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,

列:empinfodata.Columns(

empinfodata.Column(regId,format:(item)=> item.GetSelectLink(item.regID.ToString())),

empinfodata.Column( 数字,数字),

empinfodata.Column(名称,名称),

empinfodata.Column(EffectDate,Effe ctive Date),









))




@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

推荐答案

检查这个



第17部分在mvc中编辑模型 - YouTube [ ^ ]


请参阅以下链接,它可能对您有所帮助。



如何显示文本框中所选行的数据| ASP.NET Web窗体| Syncfusion [ ^ ]
See the following link, it may helpful for you.

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


这篇关于选择一个网格行应该在mvc中显示文本框中的行数据。我可以这样做吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆