473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

datagrid

How to insert textbox into datagrid and all the values in the row is inserted into the database.

pls help me anyone.
Apr 29 '08 #1
3 828
vee10
141 100+
hi ..
few days back i was also looking into the solution i got the solution

http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx

i am also just posting my code but its not using the database

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6.  
  7. <html xmlns="http://www.w3.org/1999/xhtml" >
  8. <head runat="server">
  9.     <title>Untitled Page</title>
  10. </head>
  11. <body>
  12.     <form id="form1" runat="server">
  13.     <div>
  14.     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  OnRowCancelingEdit="GridView1_RowCancelingEdit"  OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"> 
  15. <Columns> 
  16. <asp:TemplateField HeaderText="Edit" ShowHeader="False"> 
  17. <EditItemTemplate> 
  18.   <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
  19.   <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
  20. </EditItemTemplate> 
  21.  
  22. <ItemTemplate> 
  23.   <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
  24. </ItemTemplate> 
  25. </asp:TemplateField> 
  26.  
  27. <%--<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" /> --%>
  28. <asp:TemplateField HeaderText="WTTPath" SortExpression="Name"> <EditItemTemplate> 
  29.   <asp:TextBox ID="txtWTTPath" runat="server" Text='<%# Eval("WTTPath") %>'></asp:TextBox> 
  30. </EditItemTemplate> 
  31. <ItemTemplate> 
  32.   <asp:Label ID="Label2" runat="server" Text='<%# Bind("WTTPath") %>'></asp:Label> 
  33. </ItemTemplate> 
  34. </asp:TemplateField> 
  35.  
  36.  
  37.  
  38.  
  39. <asp:TemplateField HeaderText="PSPath"> 
  40. <EditItemTemplate> 
  41.   <asp:TextBox ID="txtPSPath" runat="server" Text='<%# Bind("PSPath") %>'></asp:TextBox> 
  42. </EditItemTemplate> 
  43.  
  44. <ItemTemplate> 
  45.   <asp:Label ID="Label3" runat="server" Text='<%# Bind("PSPath") %>'></asp:Label> 
  46. </ItemTemplate> 
  47. </asp:TemplateField> 
  48.  
  49.  
  50.  
  51.  
  52.  
  53. </Columns> 
  54. </asp:GridView> 
  55.  
  56.     </div>
  57.  
  58.     </form>
  59. </body>
  60. </html>
  61.  
  62.  
  63. protected void Page_Load(object sender, EventArgs e)
  64.     {
  65.         DataTable dt = new DataTable("ComponentTable");
  66.         DataRow dr = dt.NewRow();
  67.         DataColumn dc = new DataColumn("WTTPath");
  68.         dc.DataType = Type.GetType("System.String");
  69.         dt.Columns.Add(dc);
  70.         dc = new DataColumn("PSPath");
  71.         dc.DataType = Type.GetType("System.String");
  72.         dt.Columns.Add(dc);
  73.         dr["WTTPath"] = "WTTPath";
  74.         dr["PSpath"] = "PSpath";
  75.         dt.Rows.Add(dr);
  76.         GridView1.DataSource = dt;
  77.         GridView1.DataBind(); 
  78.     }
  79.  
  80.     protected void FillData()
  81.     {
  82.         DataTable dt = new DataTable("ComponentTable");
  83.         DataRow dr = dt.NewRow();
  84.         DataColumn dc = new DataColumn("WTTPath");
  85.         dc.DataType = Type.GetType("System.String");
  86.         dt.Columns.Add(dc);
  87.         dc = new DataColumn("PSPath");
  88.         dc.DataType = Type.GetType("System.String");
  89.         dt.Columns.Add(dc);
  90.         dr["WTTPath"] = "WTTPath"; //u should fill data using database not directly assigning like this
  91.         dr["PSpath"] = "PSpath";
  92.         dt.Rows.Add(dr);
  93.         GridView1.DataSource = dt;
  94.         GridView1.DataBind(); 
  95.     }
  96.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  97.     {
  98.         GridView1.EditIndex = e.NewEditIndex;
  99.         FillData();
  100.     }
  101.     protected void GridView1_RowCommand(object sender, EventArgs e)
  102.     {
  103.     }
  104.     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  105.     {
  106.         TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtWTTPath");        
  107.         TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtPSPath");
  108.         //write logic what ever u want  ie save this in database
  109.  
  110.         FillData();
  111.         GridView1.EditIndex = -1;
  112.  
  113.     } 
  114.     protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  115.     {
  116.         GridView1.EditIndex = -1;
  117.  
  118.     }
  119.  
  120.  
  121.  
How to insert textbox into datagrid and all the values in the row is inserted into the database.

pls help me anyone.
Apr 29 '08 #2
thank for ur reply
i am not using edit.but i need textbox in datagrid.then i want how to insert checkbox into datagrid or gridview.

pls help me.
Apr 29 '08 #3
vee10
141 100+
hi...

sorry for posting wrong which is not ur requirement

Expand|Select|Wrap|Line Numbers
  1.  <asp:GridView ID="GridView1" runat="server" > 
  2.         <Columns>
  3.             <asp:TemplateField HeaderText="Check">
  4.                 <EditItemTemplate>
  5.                     <asp:CheckBox ID="CheckBox1" runat="server" />
  6.                 </EditItemTemplate>
  7.                 <ItemTemplate>
  8.                     <asp:CheckBox ID="CheckBox1" runat="server" />
  9.                 </ItemTemplate>
  10.             </asp:TemplateField>
  11.             <asp:TemplateField HeaderText="dropdown">
  12.                 <EditItemTemplate>
  13.             <asp:DropDownList ID="drop" runat="server"></asp:DropDownList>
  14.                 </EditItemTemplate>
  15.                 <ItemTemplate>
  16.                     <asp:DropDownList ID="drop" runat="server"></asp:DropDownList>
  17.                 </ItemTemplate>
  18.  
  19.             </asp:TemplateField>
  20.  
  21.             <asp:TemplateField HeaderText="dropdown">
  22.                 <EditItemTemplate>
  23.                 <asp:TextBox ID="text" runat="server"></asp:TextBox>
  24.                 </EditItemTemplate>
  25.                 <ItemTemplate>
  26.                     <asp:TextBox ID="text" runat="server"></asp:TextBox>
  27.                 </ItemTemplate>
  28.  
  29.             </asp:TemplateField>
  30.         </Columns>
  31.  
  32. </asp:GridView> 
  33.  



thank for ur reply
i am not using edit.but i need textbox in datagrid.then i want how to insert checkbox into datagrid or gridview.

pls help me.
Apr 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
3
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
7
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.