Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 asp.net dropdownlist and 1 Button

dropdownlist1=(project number)

dropdownlist2=(project title)

dropdownlist3=(activity)

button =(add)

(for your info : I call the value of dropdown from list in Sharepoint2010)

I selected project number,
then I select title then activity...
press add button then all value displayed in gridview.


The problem is ,when data was insert to gridview row, it will stretch the gridview down not in html table row by row.

How to inserted it row by row in html table?
Posted

Here I have Developed following code
static DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        dt = new DataTable();
        dt.Columns.Add("Project Number");
        dt.Columns.Add("Title");
        dt.Columns.Add("Activity");
    }
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)
{
    DataRow dr = dt.NewRow();
    dr[0] =  DropDownList1.SelectedValue;
    dr[1] =  DropDownList2.SelectedValue;
    dr[2] =  DropDownList3.SelectedValue;
    dt.Rows.Add(dr);
    GridView1.DataSource = dt;
    GridView1.DataBind();
}


I hope this will be helpful to you
 
Share this answer
 
Comments
man_alansik 12-Dec-12 3:09am    
thank for the solution...
but let say I have html table.
three column

| project no | ctr no | activity |
|=dropdown= |=dropdown= | =dropdown=| add button
| -here- | -here- | -here- |


and how to make sure when we add the row , the new row is fill in the html table(-here-).
 
Share this answer
 
Comments
man_alansik 12-Dec-12 3:09am    
thanks
man_alansik 12-Dec-12 3:15am    
thank for the solution...
but let say I have html table.
three column

| project no | ctr no | activity |
|=dropdown= |=dropdown= | =dropdown=| add button
| -here- | -here- | -here- |


and how to make sure when we add the row , the new row is fill in the html table(-here-).
Follow this example:

VB
Protected Sub btnSaveEmail_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSaveEmail.Click
        dt_email = Session("dt_email") 'OR Dim dt_email As New DataTable

        Dim dr As DataRow
        dr = dt_email.NewRow()

        dr("intCodigoClienteEmail") = Cint(DropDownList.Selectedvalue)
        dr("intCodigoCliente") = Cint(DropDownList.Selectedvalue)
        dr("vchEmail") = Cint(DropDownList.Selectedvalue)

        dt_email.Rows.Add(dr)

        grdEmail.DataSource = dt_email
        grdEmail.DataBind()

        Session("dt_email") = dt_email
    End Sub



First you take a datatable existing OR can create a new one, then create a datatable DataRow this by adding a line as the selected values​​.
After all done, load the datatable with the datarow.
After that load the grid with datatable
 
Share this answer
 
I think the cleanest way to do this would be to click on the include in a Temporary table and then climb her data to the Grid
 
Share this answer
 
Comments
man_alansik 12-Dec-12 20:18pm    
sorry ... cann you explain more ...

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