Gridview - 索引超出范围

时间:2015-04-10 13:41:21

标签: javascript jquery asp.net gridview

有时候我会让索引超出范围......但是我传递了行索引,没有办法超出范围..

我的代码是c#,它有onRowCommand方法

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string commandname = e.CommandName;
            int index = int.Parse(e.CommandArgument.ToString());

            if (commandname.Equals("atender"))
            {

                string id = GridView1.Rows[index].Cells[3].Text;
                string imgvd = GridView1.Rows[index].Cells[12].Text;
                string lng = GridView1.Rows[index].Cells[10].Text;
                string lat = GridView1.Rows[index].Cells[11].Text;
                string comentarios = GridView1.Rows[index].Cells[8].Text;  

                ManifestacaoEntity mf = new ManifestacaoEntity();

                if (GridView1.Rows[index].Cells[8].Text.Equals("Aguardando"))
                {
                    mf.status = 1;
                    mf.dataatendimento = DateTime.Now;
                    mf.id = id;
                    var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
                    account.CreateCloudTableClient().CreateTableIfNotExist("fiscal");
                    var context = new CRUDManifestacoesEntities(account.TableEndpoint.ToString(), account.Credentials);
                    context.UPDATEStatus(mf);
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script> alert('Manifestação em atendimento.') ; </script>");
                }
}

在aspx中我传递了行索引。有什么不对吗?

 <asp:GridView  ID="GridView1" runat="server" CellPadding="4" 
            BorderStyle="None" BorderWidth="0px" CellSpacing="1" Width="100%" 
                GridLines="Vertical" AllowPaging="True" onrowcommand="GridView1_RowCommand" 
                onselectedindexchanged="GridView1_SelectedIndexChanged" 
                onpageindexchanging="GridView1_PageIndexChanging" 
                onrowdatabound="GridView1_RowDataBound" PageSize="5" HorizontalAlign=Left
                >
                                <PagerStyle HorizontalAlign="Center" />
                                <RowStyle CssClass="tabela_texto2" HorizontalAlign="Center" 
                                    VerticalAlign="Middle" />
                    <AlternatingRowStyle CssClass="tabela_texto1" />

            <Columns>
             <asp:TemplateField>
                  <ItemTemplate>
                  <asp:Button Text="Status" CommandName="atender" CommandArgument='<%# Container.DataItemIndex %>' ID="atender" runat="server" OnClientClick="return confirm('Tem certeza que deseja aterar os status?');" />
                  </ItemTemplate>
             </asp:TemplateField>
         <asp:ButtonField Text="Ver no mapa" CommandName="ver" ButtonType="Button" /> 
       </Columns>
        </asp:GridView>

0 个答案:

没有答案