English 中文(简体)
网格视图行编辑和删除
原标题:Gridview row editing and deleting

我有一个要更新员工确认的网格。 我需要用编辑和删除链接来改变网格中的数据。 我很难创建这个网格。 因为网格视图所有文本框总是可以使用。 文本框只有在单击编辑按钮时才启用 。

这是我的部分代码:

       <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>
问题回答

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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签