GridView如何更新批量数据和单条记录?

后台代码段

        Members
        
Events
        
Methods
 


前台html

<script language="JavaScript">

            
<!--
            
function CheckAll(val)
              
{
                
for (var i=0;i<document.forms[0].elements.length;i++)
                
{
                  
var e = document.forms[0].elements[i];
                  
if(e.Type="checkbox" && e.name!="_ctl2:_ctl0:radioSortDesc")
                  
{
                e.checked
=val;
                  }

                }

              }
             
            
//-->

</script>
<table width="95%" border="0" cellpadding="0" cellspacing="0" align="center">
    
<tr>
        
<td height="25" align="right" bgcolor="#EFEFEF" class="tab_font_right">
            
<strong>产品搜索</strong>
            
<asp:TextBox ID="txtSearchTxt" runat="server" />
            
<asp:Button ID="btnSearch" runat="server" Text="搜索"></asp:Button>
            
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;转到
            
<asp:DropDownList ID="ddlType" runat="server" CssClass="maintext" AutoPostBack="True">
                
<asp:ListItem Value="10000">所有产品</asp:ListItem>
                
<asp:ListItem Value="2">已推荐</asp:ListItem>
                
<asp:ListItem Value="1">当前发布</asp:ListItem>
                
<asp:ListItem Value="0">等待审核</asp:ListItem>
                
<asp:ListItem Value="-1">未通过审核</asp:ListItem>
                
<asp:ListItem Value="-2">未发布</asp:ListItem>
            
</asp:DropDownList>
        
</td>
    
</tr>
</table>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1">
    
<tr>
        
<td>
            
<asp:GridView ID="GVList" runat="server" ShowFooter="true" AutoGenerateColumns="False"
                BorderStyle
="Solid" BorderColor="#ffffff" GridLines="Horizontal" CellSpacing="1"
                Width
="100%" HorizontalAlign="NotSet" BorderWidth="0px" EnableViewState="true"
                DataKeyNames
="P_ID">
                
<HeaderStyle CssClass="InfoHeaderText" ForeColor="#000000" HorizontalAlign="center"
                    Height
="22px" />
                
<AlternatingRowStyle BackColor="#f7f7f7" />
                
<RowStyle HorizontalAlign="center" Height="20px" BackColor="#E3EAEB" />
                
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                
<Columns>
                    
<asp:TemplateField>
                        
<HeaderStyle Width="60px" BackColor="#1C5E55" ForeColor="White" />
                        
<HeaderTemplate>
                            编号
</HeaderTemplate>
                        
<ItemTemplate>
                            
<asp:Label ID="PKID" Text='<%# DataBinder.Eval(Container.DataItem,"P_ID")%>' runat="server" />
                        
</ItemTemplate>
                    
</asp:TemplateField>
                    
<asp:TemplateField Visible="False">
                        
<HeaderTemplate>
                            
<asp:Label ID="Image_Head" runat="server" Text="产品图片" />
                        
</HeaderTemplate>
                        
<HeaderStyle Width="120" />
                        
<ItemTemplate>
                            
<asp:HyperLink ID="P_SmallImage" runat="server" />
                        
</ItemTemplate>
                    
</asp:TemplateField>
                    
<asp:TemplateField>
                        
<HeaderTemplate>
                            
&nbsp; 产品名称</HeaderTemplate>
                        
<ItemStyle HorizontalAlign="left" />
                        
<HeaderStyle HorizontalAlign="Left" />
                        
<ItemTemplate>
                            
&nbsp;·<asp:Label ID="P_Name" Text='<%# DataBinder.Eval(Container.DataItem,"P_Name")%>'
                                runat="Server" />
<img src='<%# "/Resource/images/Check"+DataBinder.Eval(Container, "DataItem.CurState")+".gif" %>' /></ItemTemplate>
                    
</asp:TemplateField>
                    
<asp:BoundField DataField="ModTime" HeaderText="修改时间" DataFormatString="{0:yyyy-MM-dd HH:mm}"
                        HtmlEncode
="false" />
                    
<asp:BoundField DataField="ModUser" HeaderText="修改者" />
                    
<asp:TemplateField>
                        
<HeaderTemplate>
                            状态
</HeaderTemplate>
                        
<ItemTemplate>
                            
<asp:Label ID="CurState" Text='<%# GetCurStateByID(DataBinder.Eval(Container.DataItem,"CurState"))%>'
                                runat="Server" />
                        
</ItemTemplate>
                    
</asp:TemplateField>
                    
<asp:TemplateField>
                        
<HeaderStyle Width="60px" />
                        
<HeaderTemplate>
                            编辑
</HeaderTemplate>
                        
<ItemTemplate>
                            
<asp:HyperLink ID="cmdMod" CssClass="ElementNavigation" Text="编辑" runat="server" />
                        
</ItemTemplate>
                    
</asp:TemplateField>
                    
<asp:TemplateField>
                        
<HeaderStyle Width="60px" />
                        
<HeaderTemplate>
                            更新
</HeaderTemplate>
                        
<ItemTemplate>
                            
<asp:LinkButton ID="cmdUpdate" CommandName="Update" CssClass="ElementNavigation" Text="快速更新" runat="server"  OnClientClick="return confirm('您确认快速更新该记录吗?');"/>
                        
</ItemTemplate>
                    
</asp:TemplateField>
                    
<asp:TemplateField>
                        
<HeaderStyle Width="40px" />
                        
<HeaderTemplate>
                            
<input type="checkbox" name="allbox" value="Check All" onclick="CheckAll(allbox.checked);" />
                        
</HeaderTemplate>
                        
<ItemTemplate>
                            
<asp:CheckBox ID="chkDelServer" runat="server" />
                        
</ItemTemplate>
                    
</asp:TemplateField>
                
</Columns>
            
</asp:GridView>
        
</td>
    
</tr>
    
<tr>
        
<td align="right">
            
<asp:HyperLink ID="cmdAdd" ForeColor="Red" Text="新增" CssClass="ElementNavigation"
                runat
="server" />
            
&nbsp;&nbsp;<asp:LinkButton ID="cmdRecommend" runat="server" CssClass="ElementNavigation"
                Text
="推荐" CommandName="ReCommend" CausesValidation="false" OnClientClick="javascript:return confirm('确定推荐或(取消推荐)已选择的数据吗?')"></asp:LinkButton>
            
&nbsp;&nbsp;<asp:LinkButton ID="cmdUnPublish" runat="server" CssClass="ElementNavigation"
                Text
="取消发布" CommandName="UnPublish" CausesValidation="false" OnClientClick="javascript:return confirm('确定取消发布已选择的数据吗?')"></asp:LinkButton>
            
&nbsp;&nbsp;<asp:LinkButton ID="cmdDel" ForeColor="Red" Text="删除" CssClass="ElementNavigation"
                CausesValidation
="false" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('确定删除已选择的数据吗?')" />
        
</td>
    
</tr>
    
<tr>
        
<td>
            
<Agronet:Pager ID="pager" runat="server" CssClass="Pager" LinkFormatActive='<a href="{0}" class="Current">{1}</a>'
                PrefixText="页码:" UseSpacer="False" />
        
</td>
    
</tr>
</table>


值处注意的是:
必须添加这个事件,即使它什么也不干

 private void GVList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        
{
            
//BindList();
        }


否则会提示“未处理的RowUpdating事件”

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1935654

posted @ 2007-12-30 19:53  邀月  阅读(3482)  评论(0编辑  收藏  举报