Gridview行编辑和删除

时间:2012-05-25 04:41:54

标签: asp.net gridview

我有一个网格来更新员工的确认。我需要使用编辑和删除链接从网格中更改数据。我很难创建这个网格。因为gridview所有文本框都启用always.Textbox仅在单击编辑按钮时启用。

这是我的部分代码:

       <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                                        Width="100%" AutoGenerateColumns="False" CssClass="GridViewStyle" GridLines="None"
                                        ShowHeaderWhenEmpty="True" EmptyDataText="No Data Found" 
                                        onpageindexchanging="GridView1_PageIndexChanging" 
                                        AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" 
                                        onrowcancelingedit="GridView1_RowCancelingEdit" 
                                        onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing" 
                                        onrowupdating="GridView1_RowUpdating" >
                                        <Columns>
                                            <asp:TemplateField HeaderText="EMP ID">
                                                <ItemTemplate>

                                                    <asp:TextBox ID="lblempId" runat="server" Text='<%#Bind("fldemp_id") %>'></asp:TextBox>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="EMPLOYEE NAME">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="lblusername" runat="server" Text='<%#Bind("fldempname") %>'></asp:TextBox>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="JOINDATE">
                                                <ItemTemplate>
                                                   <asp:TextBox ID="lbljoin" runat="server" Text='<%#Bind("fldjoindate") %>'></asp:TextBox>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="CONFIRMATION DATE">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="lblconfirm" runat="server" Text='<%#Bind("fldconfirmdate") %>'></asp:TextBox>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                               <asp:TemplateField HeaderText="STATUS">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="lblStatus" runat="server" Text='<%#Bind("fldstatus") %>'></asp:TextBox>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                              <asp:TemplateField HeaderText="CONFIRMATION STATUS">
                                                  <ItemTemplate>
                                                      <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Eval("fldcon_status") %>' >
                                                          <asp:ListItem>Confirmed</asp:ListItem>
                                                          <asp:ListItem>Not-Confirmed</asp:ListItem>
                                                          <asp:ListItem>Extended</asp:ListItem>
                                                      </asp:DropDownList>
                                                  </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderImageUrl="~/images/edit.png">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/edit.png" CommandName="edi"
                                                        CommandArgument='<%#Bind("fldemp_id") %>' />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderImageUrl="~/images/Delete.png">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/Delete.png"
                                                        CommandName="del" CommandArgument='<%#Bind("fldemp_id") %>' />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                        <RowStyle CssClass="RowStyle" />
                                        <EmptyDataRowStyle CssClass="EmptyRowStyle" />
                                        <PagerStyle CssClass="PagerStyle" />
                                        <SelectedRowStyle CssClass="SelectedRowStyle" />
                                        <HeaderStyle CssClass="HeaderStyle" HorizontalAlign="Left" />
                                        <EditRowStyle CssClass="EditRowStyle" />
                                        <AlternatingRowStyle CssClass="AltRowStyle" />
                                    </asp:GridView>

1 个答案:

答案 0 :(得分:0)

如果您询问如何禁用网格中的编辑,直到有人点击Edit按钮,只需在网格上将Enabled属性设置为False,直到按下按钮。