Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've one row in gridview with controls one textbox,dropdownlist and a Button"ADD"...My requiremnt is to get a similar row on button click"ADD" using Javascript(We dont need server side code)...Please suggest ASAP..Thanks
Posted
Comments
I.explore.code 16-Oct-12 5:51am    
have you tried anything or something yourself first? or you thought it would just be easier if someone wrote the code for you? If you know you have to use JS then you have a very good starting point.
Naga KOTA 16-Oct-12 5:56am    
can u send me sample code upto now what you have written
AshishChaudha 16-Oct-12 6:53am    
Lets start with you code...

Please check the Question Grid Adding Row with Javascript[^] and see the implementation of the asker in that question itself.
You may get some idea and implement as per your requirement.

Thanks...
 
Share this answer
 
I did come to know that binding gridview with javascript is really challenging task .So, I solved the problem by writing code in aspx.Cs page and it did work..took CommandName and command argument property in the Button item template of Gridview and wrote the code on RowCommand event of Gridview for generating similar row..Thanks
C#
protected void grdVwCarCase_RowCommand(object sender, GridViewCommandEventArgs e)
{
   int index = Convert.ToInt32(e.CommandArgument.ToString());
   if (e.CommandName == "New")
   {
      DataTable dt = new DataTable();
      dt.Columns.Add("Parameter");
      dt.Columns.Add("Operation");
      dt.Columns.Add("text1");
      dt.Columns.Add("Condition");
      dt.AcceptChanges();
      for (int i = 0; i < grdVwCarCase.Rows.Count; i++)
      {
         DataRow dr = dt.NewRow();
         dr["Parameter"] = ((DropDownList)(grdVwCarCase.Rows[i].Cells[0].FindControl("drpFieldParameter"))).SelectedValue;
         dr["Operation"] = ((DropDownList)(grdVwCarCase.Rows[i].Cells[0].FindControl("ddlOperation"))).SelectedValue;
         dr["text1"] = ((TextBox)(grdVwCarCase.Rows[i].Cells[0].FindControl("txtFreeText"))).Text;
         dr["Condition"] = ((DropDownList)(grdVwCarCase.Rows[i].Cells[0].FindControl("ddlCondition"))).SelectedValue;
         dt.Rows.Add(dr);
         if (i == index)
         {
            DataRow dr1 = dt.NewRow();
            dt.Rows.Add(dr1);
         }
      }
      grdVwCarCase.DataSource = dt;
      grdVwCarCase.DataBind();
   }
}
 
Share this answer
 
v2
Comments
fjdiewornncalwe 16-Oct-12 14:43pm    
Sorry, but you will not pass this assignment if you hand it in this way. The reason your homework requested for you to do it using javascript was to teach you to avoid unnecessary postbacks. I would suggest that you rethink this. This will work as you have it, but it won't satisfy the requirements.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900