Simplified user interface, adding features can not be simplified, but if the GridView do display, edit, update and delete, will allow users to edit, need to click Edit the Ammonium button, then edit, or cancel the edit.
In order to solve this problem, insus.net think of some improved methods. You can refer to the following demo:
The following items were added at 2011-11-07 9:20:
This is accomplished by using the table plus the GridView to combine.
Among them, gridveiw directly using ItemTemplate template, omitted the EditItemTemplate template. Events also omit the onrowediting and Onrowcancelingedit events.
As shown below:
The contents of the EditItemTemplate are then moved to the ItemTemplate template and replaced.
The complete code reference is as follows:
Copy Code code as follows:
<asp:table id= "Table1" runat= "Server" cssclass= "Table" cellpadding= "2" cellspacing= "0" >
<asp:tableheaderrow height= "backcolor=" "#efebde" borderwidth= "1" bordercolor= "#c0c0c0" >
<asp:tableheadercell backcolor= "#efebde" borderwidth= "1" bordercolor= "#c0c0c0" >
Chinese Name
</asp:TableHeaderCell>
<asp:tableheadercell backcolor= "#efebde" borderwidth= "1" bordercolor= "#c0c0c0" width= "50%" >
中文版 Name
</asp:TableHeaderCell>
<asp:tableheadercell backcolor= "#efebde" borderwidth= "1" bordercolor= "#c0c0c0" width= "10%" >
Edit
</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:tablerow height= ">"
<asp:tablecell borderwidth= "1" bordercolor= "#c0c0c0" >
<asp:textbox id= "Txt_cname" runat= "Server"/>
</asp:TableCell>
<asp:tablecell borderwidth= "1" bordercolor= "#c0c0c0" >
<asp:textbox id= "Txt_ename" runat= "Server"/>
</asp:TableCell>
<asp:tablecell borderwidth= "1" bordercolor= "#c0c0c0" >
<asp:button id= "Buttoninsert" text= "Insert" runat= "Server" onclick= "Buttoninsert_click"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<div style= "MARGIN-TOP:3PX; margin-bottom:3px; padding:3px; " >
</div>
<asp:gridview id= "Gvcuttertype" runat= "Server" datakeynames= "Cuttertypeid" autogeneratecolumns= "false"
cellpadding= "2" cellspacing= "0" width= "100%" borderwidth= "0" bordercolor= "#c0c0c0"
onrowdeleting= "Gvcuttertype_ondeletecommand" onrowupdating= "Gvcuttertype_onupdatecommand"
rowstyle-height= "showheader=" "false" >
<Columns>
<asp:TemplateField>
<itemstyle borderwidth= "1" bordercolor= "#c0c0c0"/>
<ItemTemplate>
<asp:textbox id= "Txtcname" runat= "server" text= ' <%# Eval ("CName")%> ' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<itemstyle borderwidth= "1" bordercolor= "#c0c0c0" width= "50%"/>
<ItemTemplate>
<asp:textbox id= "Txtename" runat= "server" text= ' <%# Eval ("ename")%> ' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= "Edit" >
<itemstyle borderwidth= "1" bordercolor= "#c0c0c0" width= "5%"/>
<ItemTemplate>
<asp:button id= "Button1" runat= "Server" commandname= "Update" text= "Update"/>
</ItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= "Delete" >
<itemstyle borderwidth= "1" bordercolor= "#c0c0c0" width= "5%"/>
<ItemTemplate>
<asp:button id= "Button2" runat= "server" commandname= "delete" text= "delete"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Xxx.aspx.cs:
Copy Code code as follows:
protected void Buttoninsert_click (object sender, EventArgs e)
{
Do Insert something
}
protected void Gvcuttertype_onupdatecommand (object sender, Gridviewupdateeventargs e)
{
Do update something
}
protected void Gvcuttertype_ondeletecommand (object sender, Gridviewdeleteeventargs e)
{
Do delete something
}