SQL DB与C#ASP.NET的异步(jquery?)表或数据网格 [英] Asynchronous (jquery?) table or datagrid from SQL DB with C# ASP.NET

查看:96
本文介绍了SQL DB与C#ASP.NET的异步(jquery?)表或数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找一个控件,它会使用来自表单其他部分的数据,在按钮点击时异步填充表格或数据网格。例如,用户在具有自动完成支持的输入文本框中输入订单号,然后我希望他们能够单击按钮然后根据该订单中的选择数据填充表或数据网格(IE显示)该订单的内容为用户)。它必须是异步的,因为它是一个模态,如果我们转到一个新的页面,模态当然会丢失。我在那里看到了很多jquery网格,但是在遵循有时不存在的教程时,它们似乎都没有做任何事情。我也尝试使用普通的gridview,但这也没有做任何事情。当我说没有做任何事情时,我的意思是,代码中的一切看起来都不错,然后当他们点击按钮时,没有任何反应。



我也在建设中prebuiltASP.NET(非MVC)为我节省了css时间,但由于某种原因,使得添加任何javascript非常困难 - 例如,为了获得自定义.js文件,我必须做一个asp:literal在站点主机中并将.text定义为代码隐藏中文件的路径,这似乎并不总是有效...



请帮帮我:(



BTW - SQL语句是可靠的,这部分我知道。它从数据库中选择某些列,其中x将等于来自的输入值订单号。

I've been struggling trying to find a control that will asynchronously fill in a table or datagrid on a button click, using data from other parts of the form. For instance, the user inputs a order number in a input text box with autocomplete support, and then I'd like them to be able to click a button and then have a table or datagrid populated based upon select data from that order (I.E. display the contents of that order for the user). It has to be asynchronous because it's a modal and if we go to a new page the modal will of course be lost. I've seen a lot of jquery grids out there but none of them seem to do anything when following the sometimes nonexistant tutorials. I also tried using a plain gridview, but that didn't do anything either. When I say didn't do anything, I mean, everything looked good in code and then when they click the button, nothing happens.

I'm also building on the "prebuilt" ASP.NET (non MVC) which saved me the css time but for some reason, makes it extremely difficult to add any javascript - for instance, to get in a custom .js file I had to do an asp:literal in the site master and define the .text as a path to the file in the codebehind, and that doesn't always seem to work...

Please help me :(

BTW - the SQL statement is solid, that part I do know. It selects certain columns from a database where x will equal the value of the input from the order number.

推荐答案

很久以前,我已经确定MS AJAX已经实现了。我今天才想到:为什么不尝试更新面板?



它有效。为此,我按下按钮加载表格,然后使用下面的gridview单击按钮时保持表格。因为这两个都在updatepanel中,所以加载时没有刷新页面就好了,这意味着它对于模态是安全的。



这是一个有很好教程的网站关于如何实现和使用一个可立即运行的好样本(只要你有ajax)。 http://ajax.net-tutorials.com/controls/updatepanel-control/



这是我使用的代码。请记住,在Zurb的基础CSS框架中,所有内容都被分解为网格,所以不要介意div标签,因为网格大于显示的意义。



A long time ago, I had made sure that MS AJAX was implemented. I just thought today: why not try an updatepanel?

It works. For this, I put the button to load the table, and then used a gridview below that to hold the table when the button gets clicked. Because both of these are in an updatepanel, they load without refreshing the page just fine, which means it's safe for a modal.

Here's a website that has a good tutorial on how to implement and with a good sample that works right away (as long as you've got ajax). http://ajax.net-tutorials.com/controls/updatepanel-control/

Here's the code I used. Keep in mind that in the Foundation CSS framework by Zurb everything is broken into grids, so pay no mind to the div tags since the grid is larger than makes sense to show.

<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger controlid="getdata" eventname="Click" />
    </Triggers>
    <ContentTemplate>
        <div class="row">
            <asp:Button CssClass="button large expand" runat="server" id="getdata" OnClick="getdata_click" text="Click Here to Pull SAP Order Data"/>
        </div>
        <div>
            <asp:GridView ID="GridView1" runat="server"></asp:GridView>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>





这是后端:





Here's the backend:

protected void getdata_click(object sender, EventArgs e)
{
    string strSQLconnection = "Data Source=DATA123;Initial Catalog=blah_archive;Integrated Security=True";
    SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
    SqlCommand sqlCommand = new SqlCommand("SELECT [itemcode],[dscription],[Quantity],[ShipDate] " +
        "FROM [blah_archive].[dbo].[ls_Order] " +
        "WHERE docnum = '" + "123123123" + "' " +
        "ORDER BY [LineNum]");
    sqlCommand.Connection = sqlConnection;
    sqlConnection.Open();

    SqlDataReader reader = sqlCommand.ExecuteReader();

    GridView1.DataSource = reader;
    GridView1.DataBind();
}


这篇关于SQL DB与C#ASP.NET的异步(jquery?)表或数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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