在同一时间选择和编辑数据的解决方案 [英] solution for selecting AND editing data at the same time

查看:98
本文介绍了在同一时间选择和编辑数据的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中asp.net应用程序。

我有一个SQL Server数据库中的表有两个字段:

 字段1
注释

我需要让用户选择的字段1 和特定添加注释字段1

用户随后将发布输入回服务器

我如何做到这一点?该控件可以怎么用?有没有已经是简单的jQuery的解决方案?


解决方案

这完全取决于你的站点设置。但是,如果你有字段1的值的列表,并把它们放在一个DropDownList,你就可以选择一个,并在框中添加注释。

这也很大程度上取决于你的用户界面/工作流程。这只是许多可能的方法可以做到这一点。

code前

 < ASP:DropDownList的ID =ddlField1=服务器>
    < ASP:ListItem的>&值1 LT; / ASP:ListItem的>
    < ASP:ListItem的>&值2 LT; / ASP:ListItem的>
    < ASP:ListItem的>&值3 LT; / ASP:ListItem的>
    < ASP:ListItem的>&值4 LT; / ASP:ListItem的>
< / ASP:DropDownList的>
< ASP:文本框ID =tbComments=服务器的TextMode =多行>< / ASP:文本框>
< ASP:按钮的ID =btSubmit=服务器的OnClick =btSubmit_Click>< / ASP:按钮>< ASP:SqlDataSource的ID =sqlRecord=服务器
    将InsertCommand =InsertRecordInsertCommandType =StoredProcedure的>
    < InsertParameters>
        < ASP:参数名称=字段1类型=字符串/>
        < ASP:参数名称=注释类型=字符串/>
    < / InsertParameters>
< / ASP:SqlDataSource的>

后面

code

 公共无效btSubmit_Click(对象发件人,EventArgs的发送)
{
  //做你的数据在这里验证
  ..  //添加字段和插入
  sqlRecord.InsertParameters [字段1] =默认值ddlField1.SelectedValue。
  sqlRecord.InsertParameters [注释] =默认值tbComment.Text。
  sqlRecord.Insert();
}

这是未经测试和部分伪code,但应该让你在一般的非MVC的Web应用程序的正确方向。另外这个不使用任何的JavaScript / jQuery的,只是ASP.NET和C#。

i have an asp.net application in c#.

i have a table in a sql server database with two fields:

Field1
Comments

i need to allow the user to SELECT the Field1 and add comments for that specific Field1

the user would then post the input back to the server

how do i accomplish this? which control can i use? is there already a simple jquery solution?

解决方案

This completely depends on your site setup. However if you have a list of Field1 values and put them in a DropDownList, you'll be able to select one and add a comment in a box.

This also heavily depends on your user interface / workflows. This is just one of MANY possible ways to do this.

Code front

<asp:DropDownList ID="ddlField1" runat="server">
    <asp:ListItem>Value1</asp:ListItem>
    <asp:ListItem>Value2</asp:ListItem>
    <asp:ListItem>Value3</asp:ListItem>
    <asp:ListItem>Value4</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="tbComments" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="btSubmit" runat="server" OnClick="btSubmit_Click"></asp:Button>

<asp:SqlDataSource ID="sqlRecord" runat="server"
    InsertCommand="InsertRecord" InsertCommandType="StoredProcedure">
    <InsertParameters>
        <asp:Parameter Name="Field1" Type="String" />
        <asp:Parameter Name="Comment" Type="String" />
    </InsertParameters>
</asp:SqlDataSource>

Code behind

public void btSubmit_Click(object sender, EventArgs e)
{
  // Do your validation of the data here
  ..

  // Add fields and insert
  sqlRecord.InsertParameters["Field1"].DefaultValue = ddlField1.SelectedValue;
  sqlRecord.InsertParameters["Comment"].DefaultValue = tbComment.Text;
  sqlRecord.Insert();
}

This is untested and partial pseudo code but should get you in the right direction for a general non-MVC web app. Also this doesn't use any JavaScript / jQuery, just ASP.NET and C#.

这篇关于在同一时间选择和编辑数据的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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