如何将gridview和选定值的值从gridview中的下拉列表保存到db [英] how to save values of gridview and selected values from of dropdownlist in gridview to db

查看:59
本文介绍了如何将gridview和选定值的值从gridview中的下拉列表保存到db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

i正在为我的项目准备考勤管理,我正在填写有关教师和科目的所有细节,当我点击OK按钮时,这些值应该保存到db以及学生的所有详细信息,如姓名,编号应该从gridview中的db填充,并使用dropdownlist(present / absent)填充1列,以便教师填写特定的学生应该生成并填写所有这些值后保存到db。

hello
i am preparing attendance management for my project and i am filling all details regarding faculty and subject and when i click OK button this values should saved to db and all details of student like name,number should be populate from db in gridview and 1 column with dropdownlist (present/absent) for faculty to fill for particular student should be generated and after filling all this values save to db.

推荐答案

您应该能够在文本列中使用常规数据绑定,如下所示:



You should be able to use conventional data binding in your text columns, like so:

<asp:gridview id="gvPersons" runat="server" autogeneratecolumns="False" width="100px" xmlns:asp="#unknown">
    <columns>
        <asp:boundfield headertext="Name (long)" datafield="Name">
        <asp:templatefield headertext="ID">
          <itemtemplate>
            <asp:combobox id="comboPresent" runat="server">
            </asp:combobox>
          </itemtemplate>
        </asp:templatefield>
    </asp:boundfield></columns>
</asp:gridview>





然后对ComboBox使用TemplateField列。



要填充组合框列,您可以订阅GridView控件的RowDataBound事件,然后通过强制转换第二列的内部控件来手动设置值到一个ComboBox并相应地设置它。



Then use a TemplateField column for the ComboBox.

To populate the combo box column you can subscribe to the RowDataBound event of the GridView control, and then set the value manually there by casting the inner control of the second column to a ComboBox and setting it accordingly.


protected void myCartGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    string prodCode = myCartGridView.DataKeys[e.RowIndex].Value.ToString();
    
    // change the values
    item.Size = ((DropDownList) myCartGridView.Rows[e.RowIndex].FindControl("sizeDropDown")).SelectedValue.ToString();
    item.Quantity = ((DropDownList) myCartGridView.Rows[e.RowIndex].FindControl("quantityDropDown")).SelectedValue.ToString();
    
    // Fire the UPDATE query here in order to update the changes in database..
    
    myCartGridView.EditIndex = -1;
    FillCartGrid();
}



-KR


-KR


这篇关于如何将gridview和选定值的值从gridview中的下拉列表保存到db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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