如何上的一个按钮单击使用的GridView在ASP.net更新多行? [英] How to update multiple rows using gridview in ASP.net on a SINGLE BUTTON CLICK?

查看:111
本文介绍了如何上的一个按钮单击使用的GridView在ASP.net更新多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的功能性要求是取学生从数据库(SQL Server)的列表(3 coloums)和在网页上显示它,在每个行,用于输入数据的前一个空白字段一起。接着,以允许用户输入由学生在测试得分标记和更新这些数据库中的

The functional requirement is to fetch the list of students (3 coloums) from database (SQL Server) and display it on the web page, along with a blank field in front of each row for entering data. Next, to allow the user to enter marks scored by students in the test and update those in the database.

现在,我知道这可以通过使用GridView控件由具有更新按钮字段作为单独的coloumn来完成。但是,在这种情况下,会有一个更新按钮,在每一行前,用户需要点击每个学生(超过100个)。这是用户乏味的任务。

Now, I know this can be done using gridview by having an Update Button Field as separate coloumn. But in that case there would be an update button in front of each row and user would need to click it for each student (more than 100). This is a tedious task for user.

我要那个用户输入的所有学生的标记,然后单击只有1按钮,这将更新所有行。

I want that user enters the marks for all the students and then click only 1 button, which would update all the rows.

在按钮单击事件,我们可以使用GridViewRows foreach循环,但请帮我的用户界面。如何使它可能?如何使用一键点击,而不是'N'点击??

On button click event we can use foreach loop for GridViewRows, but please help me with user interface. How to make it possible?? How to use single button click instead of 'n' clicks??

可以使用它GridView的做?还是有别的东西可以完成这个任务?

Can it be done using gridview? Or is there something else which can accomplish the task??

感谢

推荐答案

将模板字段中的文本框在第四列

place a textbox inside template field in fourth column

<asp:TemplateField HeaderText="Marks Scored">
    <ItemTemplate>
        <asp:TextBox runat="server" ID="txtMarksScored" />
    </ItemTemplate>
</asp:TemplateField>

然后通过内部网格视图行按钮单击事件循环,让文本框来获取值输入。

Then inside button click event loop through grid view rows and get the textbox to get the value entered.

protected void Submit_Click(object sender, EventArgs e)
{
    foreach (GridViewRow gvr in GridView1.Rows)
    {
        TextBox txtMarksScored = (TextBox)gvr.FindControl("txtMarksScored");
        // Hope you understand what to do next?
        // txtMarksScored.Text
    }
}

这篇关于如何上的一个按钮单击使用的GridView在ASP.net更新多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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