【问题标题】:I want to insert database value in grid view editable text box from which I can update that text box [closed]我想在网格视图可编辑文本框中插入数据库值,我可以从中更新该文本框 [关闭]
【发布时间】:2013-02-10 10:22:03
【问题描述】:
<asp:GridView ID="grdAttendance1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                        ForeColor="#333333" GridLines="None" Width="100%" HorizontalAlign="Center">
                        <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <asp:BoundField DataField="InstID" HeaderText="College ID" />
                            <asp:BoundField DataField="Fid" HeaderText="Employee ID" />
                            <asp:BoundField DataField="FName" HeaderText="Employee Name" />
                            <asp:BoundField DataField="Designation" HeaderText="Designation" />
                            <asp:BoundField DataField="Department" HeaderText="Department" />
                            <asp:BoundField DataField="Date" HeaderText="Date" />
                            <asp:TemplateField HeaderText="In Time">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtIntime1" runat="server"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Out Time">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtOuttime1" runat="server"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Leave Type">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtLeaveType1" runat="server"></asp:TextBox>
                                </ItemTemplate>
                             </asp:TemplateField>
                        </Columns>
                        <EditRowStyle BackColor="#2461BF" />
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#EFF3FB" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#F5F7FB" />
                        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                        <SortedDescendingCellStyle BackColor="#E9EBEF" />
                        <SortedDescendingHeaderStyle BackColor="#4870BE" />
                    </asp:GridView>

我拿了这个,但它没有与数据库绑定,文本框显示为空白。

【问题讨论】:

    标签: asp.net gridview visual-studio-2008


    【解决方案1】:

    首先推荐浏览Microsoft's ASP.NET data access tutorials

    我会给你一个通用指南,让你走上正轨

    1. 添加如下命令字段:<asp:CommandField ButtonType=”Link” ShowEditButton=”true” ShowDeleteButton=”true” ShowCancelButton=”true” />
    2. 将您不想编辑的任何字段设置为readonly="true"
    3. 为可编辑的模板字段添加EditItemTemplates
    4. 填写您的事件处理程序,例如editindexchanged、updated、deleted、edit-canceled等See GV Events here (MSDN)
      • 在 Row_Updating 事件中实现保存到数据库的代码。

    第一次做这件事可能有点棘手,但一旦你完成它就很容易了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 2022-10-20
      • 2020-08-20
      • 1970-01-01
      相关资源
      最近更新 更多