0

i have GridView.AutoGenerateColumn=true.

i have created button on footer on rowdatabound when i click on button row command event is not fired

Here is my code:

dt = ESalesUnityContainer.Container.Resolve<IAgentService>().GetAgentMaterialPercentage();
grdMaterialPercentage.DataSource = dt;
grdMaterialPercentage.DataBind();

protected void grdMaterialPercentage_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (grdMaterialPercentage.AutoGenerateColumns == true)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].Visible = false;
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Visible = false;
            if (DataBinder.Eval(e.Row.DataItem, "AgentName").ToString() != string.Empty)
            {
                int i = 0;
                foreach (TableCell c in e.Row.Cells)
                {
                    if (i >= 3)
                    {
                        TextBox tb = new TextBox();
                        tb.Text = c.Text;
                        tb.Style.Add("Width", "25px");
                        tb.Style.Add("Height", "15px");
                        c.Controls.Clear();
                        c.Controls.Add(tb);

                    }
                    i++;
                }
            }
            else
            {
                e.Row.Visible = false;
            }
        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Visible = false;
            int j = 0;
            foreach (TableCell c in e.Row.Cells)
            {

                if (j >= 3)
                {
                    DataRow dr = dt.Rows[dt.Rows.Count - 1];
                    LinkButton btn = new LinkButton();

                    btn.ID = j.ToString();

                    btn.CommandName ="fghfh"+j.ToString();
                    btn.Text = "Save" + dr[j - 1].ToString();
                    btn.CssClass = "button";
                    btn.Style.Add("align", "center");
                    btn.CommandArgument = dr[j - 1].ToString();
                  //  btn.OnClientClick = "return ValidateTotalPercentage(this)";
                    c.Controls.Clear();
                    c.Controls.Add(btn);

                } j++;
            }
        }
    }
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
SMeha
  • 61
  • 3
  • 8

2 Answers2

1

Where are the first lines(f.e. grdMaterialPercentage.DataBind()) located? If in Page_Load, are you binding the GridView only if !Page.IsPostback? Otherwise the GridView gets bound to the datasource again what prevents the RowCommand-Event from being triggered.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
1

Have you handled Row_Command event?You will have to check the appropriate command and then maybe test it:

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
      if (e.CommandName == "Select")
      {
          int num = Convert.ToInt32(e.CommandArgument);

          instTextBox.Text = GridView1.Rows[num].Cells[1].Text;

          //Or you can also do dis
          //Set Label lblTest.text = "It Executes"; 
          //just to check if your code reaches here
      }
  }

This will put your Command Argument into a Text Box, or you can simply put some text in a label and check,whether it's executed.

Pavitar
  • 4,282
  • 10
  • 50
  • 82