在gridview模板列中放一个Button按钮,当点击按钮时,获取该行某一字段的值,咋取值啊?

解决方案 »

  1.   


     <asp:TemplateField HeaderText="推荐">
                        <ItemTemplate  >
                            <asp:LinkButton CausesValidation="False" CommandArgument='<%#Eval("M_ID") %>' CommandName="M_flag" ID="LbtnFlag" runat="server" Text='<%#Eval("M_flag").ToString()=="0"?"不推荐":"推荐"%>'  ></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "M_flag")
            {
                dal.ChangeMerchantsFlag(Convert.ToInt16(e.CommandArgument));
                 // 参考.          找你想要的
            }
        }
      

  2.   

    string str = GridView1.Rows[i].Cells[0].Text;
    i是行索引
      

  3.   

    protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
            {
               
                if(e.CommondName=="select")
                {
                  string infostr = e.Row.Cells[1].Text;
                }
            }
      

  4.   

    给Button加上CommandName属性
    然后结合6楼的使用
      

  5.   


    <asp:TemplateField HeaderText="点击">
          <ItemTemplate>
              <asp:Button ID="ButtonClick" runat="server" CommandArgument='<%# Eval("id") %>' CommandName="ClickButton" />
          </ItemTemplate>
    </asp:TemplateField>
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (null != e.CommandName)
        {
            string cmd = e.CommandName;
            int id = 0;
            if (null != e.CommandArgument)
            {
                id = Convert.ToInt32(e.CommandArgument);
                if ("ClickButton".Equals(cmd))
                {
                      // 根据id查找你想得到字段值
                  }
            }
        }
    }
      

  6.   

    最好是把要获取的值用CommandArgument绑定了
      

  7.   

      <asp:LinkButton  CommandArgument='<%#Eval("那个字段") %>'></asp:LinkButton>