我在页面中添加了DataGrid控件,
<asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="SqlDataSource1" DataKeyField="a" OnCancelCommand="DataGrid1_CancelCommand"
OnEditCommand="DataGrid1_EditCommand"
OnItemCommand="DataGrid1_ItemCommand">
<Columns>
<asp:EditCommandColumn EditText="编辑" UpdateText="更新" CancelText="取消">
</asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
事件:
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
Response.Write("a");
}
单击"编辑"时正常,在单击"更新"时程序并不触发DataGrid1_UpdateCommand事件这是为什么?
我追踪了e.CommandName,其值一直是"Edit"
大哥帮忙!谢谢
<asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="SqlDataSource1" DataKeyField="a" OnCancelCommand="DataGrid1_CancelCommand"
OnEditCommand="DataGrid1_EditCommand"
OnItemCommand="DataGrid1_ItemCommand">
<Columns>
<asp:EditCommandColumn EditText="编辑" UpdateText="更新" CancelText="取消">
</asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
事件:
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
Response.Write("a");
}
单击"编辑"时正常,在单击"更新"时程序并不触发DataGrid1_UpdateCommand事件这是为什么?
我追踪了e.CommandName,其值一直是"Edit"
大哥帮忙!谢谢
<head runat="server">
<title>无标题页</title> <script language="javascript" type="text/javascript">
function checkall()
{
var chk= document.forms[0];
for(i=0;i<chk.elements.length;i++)
{
if(chk.elements[i].type=="checkbox")
{
chk.elements[i].checked = true;
}
}
}
function checkfalse()
{
var chk= document.forms[0];
for(i=0;i<chk.elements.length;i++)
{
if(chk.elements[i].type=="checkbox")
{
if(chk.elements[i].checked==true)
{
chk.elements[i].checked=false;
}
else
{
chk.elements[i].checked=true;
}
}
}
}
</script></head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="5" AllowPaging="True"
AutoGenerateColumns="False" Height="158px" OnRowEditing="GridView1_RowEditing"
Width="553px" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit"
DataKeyNames="TID" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="checkbox">
<HeaderTemplate>
Header
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TID" HeaderText="ID" ReadOnly="True" />
<asp:TemplateField HeaderText="Title">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# GetSocs() %>"
DataTextField="Ttitle" DataValueField="Ttitle" SelectedValue='<%# Eval("Ttitle") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Ttitle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Tinfo" HeaderText="Tinfo" />
<asp:BoundField DataField="Cinfo" HeaderText="Cinfo" />
<asp:CommandField ShowEditButton="True" HeaderText="编辑" />
<asp:TemplateField HeaderText="delete">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Image/橙色/webdesignicon_295.png"
CommandName="delete" OnClientClick="javascript:confirm('你确定要删除此记录吗?')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="删除选中项" CommandName="delete" OnClick="Button1_Click" />
<input id="rad1" type="radio" onclick="checkall()" name="selchk" />全选
<input id="rad2" type="radio" onclick="checkfalse()" name="selchk" />反选
</div>
</form>
</body>
</html>