关于asp.net中gridview的问题 [英] Question about gridview in asp .net

查看:63
本文介绍了关于asp.net中gridview的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我尝试了以下但错误来了



protected void GridApprove_RowDataBound(object sender,GridViewRowEventArgs e)

{

if(e.Row.RowType == DataControlRowType.DataRow)

{



标签lbl_pending = new Label() ;

标签lbl_approved = new Label();

int val_approved = Convert.ToInt32(e.Row.Cells [17] .ToString());

int val_checked = Convert.ToInt32(e.Row.Cells [18] .ToString());

if(val_approved == 2 && val_checked == 2)

{

Button btn_accept = new Button();

Button btn_discard = new Button();

btn_accept.Text =ACCEPT ;

btn_discard.Text =DISCARD;

e.Row.Cells [7] .Controls.Add(btn_accept);

e.Row.Cell s [7] .Controls.Add(btn_discard);

}



//tbox.Text=你没有添加的文字或与数据字段绑定;

//e.Row.Cells[7].Controls.Add(tbox),

}





生成的异常{指定的参数超出了有效值的范围。\\\\参数名称:索引}



当我在17列和18列的数据表中检索数据时,我想要获取的值,所以plz帮助我

Hello I tried the followning but the error come

protected void GridApprove_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

Label lbl_pending = new Label();
Label lbl_approved = new Label();
int val_approved = Convert.ToInt32(e.Row.Cells[17].ToString());
int val_checked = Convert.ToInt32(e.Row.Cells[18].ToString());
if (val_approved == 2 && val_checked == 2)
{
Button btn_accept = new Button();
Button btn_discard = new Button();
btn_accept.Text = "ACCEPT";
btn_discard.Text="DISCARD";
e.Row.Cells[7].Controls.Add(btn_accept);
e.Row.Cells[7].Controls.Add(btn_discard);
}

//tbox.Text= "the text you wasnt to add or bind with data field";
//e.Row.Cells[7].Controls.Add(tbox);
}


The exception generated that {"Specified argument was out of the range of valid values.\r\nParameter name: index"}

When I retrive the data in data table in that in the 17 column and 18 column the value I want to fetch so plz help me

推荐答案

下面是实现此目的的一种方法的参考代码。



Below is the reference code of one way to achieve this.

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
            Height="100px">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="btn1" runat="server" Text="Approve" CommandArgument= />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>







protected void Page_Load(object sender, EventArgs e)
     {
         string [] dataSource = { "3","1", "2" };
         if (!IsPostBack)
         {
             GridView1.DataSource = dataSource;
             GridView1.DataBind();
         }
     }

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
     {

         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             if (e.Row.DataItem.ToString() == "1")
             {
                 var cont = e.Row.FindControl("btn1");
                 e.Row.Cells[0].Controls.Remove(cont);
                 e.Row.Cells[0].Text = "Not Approved";
             }
         }
     }


这篇关于关于asp.net中gridview的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆