how to show multiple textboxes values in gridview using javascript? [Resolved]

Posted by Hariinakoti under JavaScript on 10/1/2012 | Points: 10 | Views : 7494 | Status : [Member] | Replies : 4
Hi All,
I have multiple textboxes i entering values in that textboxes after that i click on button then that values are display i gridview with saving data in database using javascript.If any body know that code plz reply to me asap

Thanks & Regards
Hari



Responses

Posted by: Divyaselvarathinam on: 10/4/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi this may suit your need as per my knowledge:

You couldnt display a gridview without a bound filed , so u should have a dummy row that is created in run time and also a dummy column in all rows.

Client side code for gridview and button :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" >

<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />


<asp:TemplateField HeaderText="Name">

<ItemTemplate>

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>

</ItemTemplate>

</asp:TemplateField>


<asp:TemplateField HeaderText="City">

<ItemTemplate>

<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>

</ItemTemplate>

</asp:TemplateField>


</Columns>
</asp:GridView>

<asp:Button ID="Button1" runat="server" OnClientClick="return AddNewRecord();" Text="Button" />

javascript:

---To add new row--

function AddNewRecord() {
var grd = document.getElementById('GridView1');
var tbod = grd.rows[0].parentNode;

var newRow = grd.rows[grd.rows.length - 1].cloneNode(true)
tbod.appendChild(newRow);

addvalue();
return false;

}

---To add textboxvalues---

function addvalue() {
var grd = document.getElementById('GridView1');
var txt = document.getElementById('TextBox1');
var id = 2;
var no=grd.rows.length - 1
grd.rows[no].cells[2].childNodes[0].value = txt.value;
}

-----Here i have added for one cell and u can add as per ur wish----

Server side code for gridview on page load event---

Dim dt As DataTable = New DataTable
Dim dr As DataRow = Nothing
dt.Columns.Add(New DataColumn("RowNumber", GetType(System.String)))
dt.Columns.Add(New DataColumn("Column1", GetType(System.String)))
dt.Columns.Add(New DataColumn("Column2", GetType(System.String)))
dt.Columns.Add(New DataColumn("Column3", GetType(System.String)))
dt.Columns.Add(New DataColumn("hdf", GetType(System.String)))
Dim i As Integer


dr = dt.NewRow
dr("RowNumber") = 1
dr("Column1") = String.Empty
dr("Column2") = String.Empty
dr("Column3") = String.Empty
dt.Rows.Add(dr)

ViewState("CurrentTable") = dt
GridView1.DataSource = dt
GridView1.DataBind()



Divya

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divyaselvarathinam on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
Are u using javascript to store values in database?
Pls elaborate ur question....

Divya

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down

@divya,
need not to store values in database.I want display values in gridview only

Thanks & Regards
Hari

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 10/4/2012 [Member] Starter | Points: 25

Up
0
Down
Thanq Divya

Thanks & Regards
Hari

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response