使列在ASP.net GridView中可编辑 [英] Making a column editable in an ASP.net GridView

查看:56
本文介绍了使列在ASP.net GridView中可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView,其中一列用于显示字段的显示顺序,这些字段将显示在我的网站的前端.不必进入编辑页面中的每个记录并以这种方式更改顺序,而是可以单击按钮并使整个DisplayOrder(int)可编辑,这样会更加方便,因此使工作变得更加轻松.该怎么办?

I have a GridView where one of the columns is for a display order for the fields where they will be shown on the front end of my website. Instead of going into each record in the edit page and having to change the order this way, it would be handier to be able to click a button and have the whole DisplayOrder (int) editable, therefore making life alot easier. How can this be done?

推荐答案

尝试以下代码:

 <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem>Manager1</asp:ListItem>
                <asp:ListItem>Manager2</asp:ListItem>
                <asp:ListItem>Manager3</asp:ListItem>
                <asp:ListItem>Manager4</asp:ListItem>
            </asp:ListBox>
            <asp:GridView ID="UserAllocationGrid" runat="server"
                AutoGenerateColumns="False">
            <Columns>

                <asp:BoundField DataField="Manager" HeaderText="Manager"
                    SortExpression="managers" />
                    <asp:TemplateField HeaderText="Allocation Percentage">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"
                            Text= '<%# Bind("AllocationPercentage") %>' BorderStyle="None"></asp:TextBox>
                    </ItemTemplate>
                    </asp:TemplateField>

            </Columns>
            </asp:GridView>

隐藏代码

     void fillGV()
        {
            DataTable UserAllocationTable = new DataTable();

            UserAllocationTable.Columns.Add("Manager");
            UserAllocationTable.Columns.Add("AllocationPercentage");
            // go through listbox1 to find selected managers = selectedManagersList 
            List<string> selectedManagersListDates = new List<string>();
            int counterR = 0;
            foreach (ListItem strItem in ListBox1.Items)
            {                     
                    //selectedManagersListDates.Add(strItem.Value); 
                    DataRow drManagerName = UserAllocationTable.NewRow();
                    UserAllocationTable.Rows.Add(drManagerName);
                    UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value;
                    counterR = counterR + 1;            
            }
           // ViewState["UserAllocationTable"] = UserAllocationTable;
            UserAllocationGrid.DataSource = UserAllocationTable;
            UserAllocationGrid.DataBind(); 
        }

在任何我单击按钮的情况下都使用此空白

Use this void in any event I did it in abutton click

      protected void Button1_Click(object sender, EventArgs e)
        {
            fillGV();

        }

这篇关于使列在ASP.net GridView中可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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