<asp:GridView ID="gvParty" runat="server" AllowPaging="True" AutoGenerateColumns="False"
       BackColor="White" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="1px"
       CellPadding="4" Font-Size="12px" HorizontalAlign="Left" OnPageIndexChanging="gvParty_PageIndexChanging" 
       PageSize="15" Width="830px" OnRowDataBound="gvParty_RowDataBound"  OnPageIndexChanged="gvParty_PageIndexChanged" AllowSorting="True" OnSorting="gvParty_Sorting"   OnRowCommand="gvParty_RowCommand" OnSorted="gvParty_Sorted" >
       <PagerSettings FirstPageText="第一页" LastPageText="最后一页" Mode="NextPreviousFirstLast"
         NextPageText="下一页" PreviousPageText="上一页" />
         
        
       <FooterStyle BackColor = "#EFEFEF" ForeColor = "#000D47" />
        <Columns>
        <asp:TemplateField>
                <HeaderTemplate>
                   <asp:CheckBox ID="ckbSelect" runat="server" Text="全选" OnCheckedChanged="CheckAll"  Width="60px" AutoPostBack="True"/>
                </HeaderTemplate>
                <ItemTemplate>
                  <asp:CheckBox ID="ItemCheckBox"  runat="server" />
                </ItemTemplate>
              </asp:TemplateField> 
            <asp:BoundField DataField="PARTYID" HeaderText="活动编号" SortExpression="PARTYID">
                <HeaderStyle Width="8%" />
                <ItemStyle HorizontalAlign="Left"  />
            </asp:BoundField>
            <asp:BoundField DataField="PARTYNAME" HeaderText="活动名称" SortExpression="PARTYNAME">
                <HeaderStyle Width="15%" />
                <ItemStyle HorizontalAlign="Left"  />
            </asp:BoundField>
            <asp:BoundField DataField="OPER" HeaderText="创建人" SortExpression="OPER">
                <HeaderStyle Width="6%" />
            </asp:BoundField>
            
            <asp:BoundField DataField="MADEDATE" HeaderText="创建日期" DataFormatString="{0:yyyy-MM-dd}"  HtmlEncode="false" SortExpression="MADEDATE">
                <HeaderStyle Width="10%" />
            </asp:BoundField>
            
                                
             <asp:BoundField DataField="partydate" HeaderText="活动日期" DataFormatString="{0:yyyy-MM-dd}"  HtmlEncode="false" SortExpression="partydate">
                <HeaderStyle Width="10%" />
            </asp:BoundField>
            <asp:BoundField DataField="status" HeaderText="活动情况" SortExpression="status" HeaderStyle-Width="8%"/>
            <asp:BoundField DataField="EXTRA" HeaderText="备注">          
                <HeaderStyle Width="20%"  />
                <ItemStyle HorizontalAlign="Left"  />
            </asp:BoundField>
            <asp:CommandField EditText="单项表制定" HeaderText="单项表制定" ShowEditButton="True" >
                <HeaderStyle Width="9%" />
            </asp:CommandField >
              
            <asp:TemplateField HeaderText="编辑"  HeaderStyle-Width="7%">
                
                <ItemTemplate>
                  <asp:button  ID="btnSelect" Text="修改"  runat="server" CommandArgument='<%# Eval("Partyid") %>' CommandName="getID"  />
                </ItemTemplate>
              </asp:TemplateField> 
                        
        </Columns>
        
        <RowStyle ForeColor="#003399" HorizontalAlign="Center" BorderColor="White" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Right" />
        <HeaderStyle BackColor="#003399" BorderStyle="None" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#EFEFEF" />
    </asp:GridView>
这是gridview

解决方案 »

  1.   

    protected void gvParty_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "getID")
            {
                Button btn = e.CommandSource as Button;
                GridViewRow row = btn.Parent.Parent as GridViewRow;
                if (btn.Text == "修改")
                {                foreach (GridViewRow gvr in gvParty.Rows)
                    {
                        Button ch = (Button)gvr.FindControl("btnSelect");
                        ch.Text = "修改";
                    }                gvParty.SelectedIndex = row.RowIndex;
                    GridViewRow r = gvParty.SelectedRow;
                    this.tbPartyID.Text = r.Cells[1].Text.ToString();
                    this.tbPartyname.Text = r.Cells[2].ToolTip.ToString();
                    if (r.Cells[4].Text.ToString().Trim() != "" && r.Cells[4].Text.ToString().Trim() != "&nbsp;")
                    {
                        this.tbYear.Text = DateTime.Parse(r.Cells[4].Text.ToString().Trim()).ToString("yyyy");
                    }
                    this.tbUsername.Text = r.Cells[3].Text.ToString();
                    this.ddlPartyCon.SelectedValue = r.Cells[6].Text.ToString();
                    this.tbBackup.Text = r.Cells[7].ToolTip.ToString();
                    if (r.Cells[4].Text.ToString().Trim() != "" && r.Cells[4].Text.ToString().Trim() != "&nbsp;")
                    {
                    this.tbStartData.Value = DateTime.Parse(r.Cells[4].Text.ToString().Trim()).ToString("yyyy-MM-dd");
                    }
                    if (r.Cells[5].Text.ToString().Trim() != "" && r.Cells[5].Text.ToString().Trim() != "&nbsp;")
                    {
                        this.tbSD.Value = DateTime.Parse(r.Cells[5].Text.ToString().Trim()).ToString("yyyy-MM-dd");
                    }                this.cbBackup.Checked = true;
                    this.cbMadeDate.Checked = true;
                    this.cbPartyCon.Checked = true;
                    this.cbPartyID.Checked = true;
                    this.cbUsername.Checked = true;
                    this.cbYear.Checked = true;
                    this.cbPartyname.Checked = true;
                    this.cbPartyDate.Checked = true;
                    this.tbYear.Enabled = false;
                    this.tbStartData.Disabled = true;                this.cbPartyID.Enabled = false;
                    this.cbBackup.Enabled = false;
                    this.cbMadeDate.Enabled = false;
                    this.cbPartyCon.Enabled = false;
                    this.cbUsername.Enabled = false;
                    this.cbYear.Enabled = false;
                    this.cbPartyname.Enabled = false;
                    this.tbPartyID.Enabled = false;                this.tbFinData.Visible = false;
                    this.tbFD.Visible = false;                this.btnSearch.Enabled = false;
                    this.btnDel.Enabled = false;               
                    btn.Text = "取消";
                    this.btnComfirm.Text = "确认";
                }
                else
                {
                    disselectindex();                btn.Text = "修改";
                }
            }
        }
      

  2.   

    点击分页、排序,统统无效。下面提示javascrip:_doPostBack('gvParty','...');都是正确的,这到底是怎么了?
      

  3.   

    生成的html很长不知道要哪段?
      

  4.   

    生成后的html
     
    <table style="background-color:ButtonFace; width:830px" > 
        <div>
    <table cellspacing="0" cellpadding="4" align="Left" rules="all" bordercolor="#0000C0" border="1" id="gvParty" style="background-color:White;border-color:#0000C0;border-width:1px;border-style:Solid;font-size:12px;width:830px;border-collapse:collapse;">
    <tr style="color:White;background-color:#003399;border-style:None;font-weight:bold;">
    <th scope="col">
                       <span style="width:60px;"><input id="gvParty__ctl1_ckbSelect" type="checkbox" name="gvParty:_ctl1:ckbSelect" onclick="javascript:setTimeout('__doPostBack(\'gvParty$_ctl1$ckbSelect\',\'\')', 0)" language="javascript" /><label for="gvParty__ctl1_ckbSelect">全选</label></span>
                    </th><th scope="col" style="width:8%;"><a href="javascript:__doPostBack('gvParty','Sort$PARTYID')" style="color:White;">活动编号</a></th><th scope="col" style="width:15%;"><a href="javascript:__doPostBack('gvParty','Sort$PARTYNAME')" style="color:White;">活动名称</a></th><th scope="col" style="width:6%;"><a href="javascript:__doPostBack('gvParty','Sort$OPER')" style="color:White;">创建人</a></th><th scope="col" style="width:10%;"><a href="javascript:__doPostBack('gvParty','Sort$MADEDATE')" style="color:White;">创建日期</a></th><th scope="col" style="width:10%;"><a href="javascript:__doPostBack('gvParty','Sort$partydate')" style="color:White;">活动日期</a></th><th scope="col" style="width:8%;"><a href="javascript:__doPostBack('gvParty','Sort$status')" style="color:White;">活动情况</a></th><th scope="col" style="width:20%;">备注</th><th scope="col" style="width:9%;">单项表制定</th><th scope="col" style="width:7%;">编辑</th>
    </tr><tr align="center" onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFEFD5'" onmouseout="this.style.backgroundColor=currentcolor" style="color:#003399;border-color:White;">
    <td>
                      <input id="gvParty__ctl2_ItemCheckBox" type="checkbox" name="gvParty:_ctl2:ItemCheckBox" />
                    </td><td align="left">P07005</td><td title="舒服" align="left">舒服</td><td>舒服]</td><td>2007-02-01</td><td title="&amp;nbsp;">&nbsp;</td><td>未制定</td><td align="left">真舒服</td><td><a href="javascript:__doPostBack('gvParty','Edit$0')" style="color:#003399;">单项表制定</a></td><td>
                      <input type="submit" name="gvParty:_ctl2:btnSelect" value="修改" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;gvParty:_ctl2:btnSelect&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" language="javascript" id="gvParty__ctl2_btnSelect" />
                    </td>
    </tr><tr align="center" onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFEFD5'" onmouseout="this.style.backgroundColor=currentcolor" style="color:#003399;background-color:#EFEFEF;border-color:White;">
    <td>
                     
                      <input id="gvParty__ctl4_ItemCheckBox" type="checkbox" name="gvParty:_ctl4:ItemCheckBox" />
                    </td><td align="left">P07007</td><td title="111111" align="left">111111</td><td>131</td><td>2007-02-01</td><td title="&amp;nbsp;">&nbsp;</td><td>未制定</td><td align="left">444</td><td><a href="javascript:__doPostBack('gvParty','Edit$2')" style="color:#003399;">单项表制定</a></td><td>
                      <input type="submit" name="gvParty:_ctl4:btnSelect" value="修改" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;gvParty:_ctl4:btnSelect&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" language="javascript" id="gvParty__ctl4_btnSelect" />
                    </td>
    </tr><tr align="center" onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFEFD5'" onmouseout="this.style.backgroundColor=currentcolor" style="color:#003399;background-color:#EFEFEF;border-color:White;">
    <td>       
                      
                      <input id="gvParty__ctl15_ItemCheckBox" type="checkbox" name="gvParty:_ctl15:ItemCheckBox" />
                    </td><td align="left">P137F</td><td title="0613参观16届华交会" align="left">0613参观16...</td><td>陈纪炎</td><td>2006-03-02</td><td title="&amp;nbsp;">&nbsp;</td><td>未制定</td><td align="left">&nbsp;</td><td><a href="javascript:__doPostBack('gvParty','Edit$13')" style="color:#003399;">单项表制定</a></td><td>
                      <input type="submit" name="gvParty:_ctl15:btnSelect" value="修改" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;gvParty:_ctl15:btnSelect&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" language="javascript" id="gvParty__ctl15_btnSelect" />
                    </td>
    </tr><tr align="center" onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFEFD5'" onmouseout="this.style.backgroundColor=currentcolor" style="color:#003399;border-color:White;">
    <td>
                      <input id="gvParty__ctl16_ItemCheckBox" type="checkbox" name="gvParty:_ctl16:ItemCheckBox" />
                    </td><td align="left">P138F</td><td title="0614参加汽车园桌会议" align="left">0614参加汽车...</td><td>陈纪炎</td><td>2006-04-10</td><td title="&amp;nbsp;">&nbsp;</td><td>未制定</td><td align="left">&nbsp;</td><td><a href="javascript:__doPostBack('gvParty','Edit$14')" style="color:#003399;">单项表制定</a></td><td>
                      <input type="submit" name="gvParty:_ctl16:btnSelect" value="修改" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;gvParty:_ctl16:btnSelect&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" language="javascript" id="gvParty__ctl16_btnSelect" />
                    </td>
    </tr><tr align="right" style="color:White;background-color:#2461BF;">
    <td colspan="10"><table border="0">
    <tr>
    <td><a href="javascript:__doPostBack('gvParty','Page$Next')" style="color:White;">下一页</a></td><td><a href="javascript:__doPostBack('gvParty','Page$Last')" style="color:White;">最后一页</a></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </div>
       </table>
       
       
      

  5.   

    生成后的html最后一段<script type="text/javascript">
    <!--
    var Page_ValidationSummaries =  new Array(document.getElementById("ValidationSummary1"));
    var Page_Validators =  new Array(document.getElementById("CompareValidaton2"), document.getElementById("CompareValidator1"), document.getElementById("CompareValidator3"), document.getElementById("CompareValidator4"));
    // -->
    </script><input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWUwK1/5ysCAKV/JexDAKQhZmxDALo0NjcDQLd2dncDQKRy4SQCwL+zoSQCwK/t6y4BwLStq24BwLfj4zMBgLQk4zMBgK+/OfDAwLHs5yrBALZ7IvSCAKhuYTSCAKi6P/4BQKs+N2NDgL14cO3CgK7lrftBwLTmYxeAtXl3r0GAoP3kqkJAujQ7NcKApf2n+IEApjF1vUFAqWf8+4KAr6u804Cra3R6wsCi5OlxgUCvtnMywMC7MK/rQQCgNj5qg8C2PTd+QwCqJCH5AICh/DQmgEC7dXJzQ0ChrCHxA4CyuSEvgYCwr76vgUCp4S8xA4CyuSAvgYCq436vgUCrNq1xA4CyuS8vgYCqPX5vgUCjfK3xA4CyuS4vgYCqf75vgUCyomxxA4CyuSUvgYCruT5vgUCy+OzxA4CyuSQvgYCp+35vgUC8MasxA4CyuSMvgYC9NT5vgUC0ZyuxA4CyuSIvgYC9d35vgUCj6z8hgUCyuSkvgYCl6ia6gkCj6yA3gsCyuSgvgYCl6iejgoClqy0vQYCiOml2Q8Cl6jyrQsClqz4rA8C7f7HzAUCl6iW0gsCjKzM5A8Cwsfh8wsCl6iK6ggCkazQuwYCp62DmQECl6iOjgkCkKyEyQUC5Mzc8gYCl6iirgoC6YaLuAMC/aPA2gYfsdsz/Oez6UPADl915VE7R7fGog==" /><script type="text/javascript">
    <!--
    var Page_ValidationActive = false;
    if (typeof(ValidatorOnLoad) == "function") {
        ValidatorOnLoad();
    }function ValidatorOnSubmit() {
        if (Page_ValidationActive) {
            return ValidatorCommonOnSubmit();
        }
        else {
            return true;
        }
    }
    // -->
    </script>
            </form>
    </body>
    </html>
      

  6.   

    validgroup怎么加?能详细说说吗?