how to make a gridview editable [modified]
-
I made a simple gridview in asp.net using the code written below. Now I want to make it editable so that at run time user can enter some data. Also,I dont want to put a thing like "edit button" ,i.e a user can simply edit a cell as he does in an excel spreadsheet. Can anybody tell me which event make the gridview editable ( I am not using any database) ? If possible, please give some code to help me understand. protected void Page_Load(object sender, EventArgs e) { dt = new DataTable(); Char[] alpha = { '#', 'A', 'B', 'C', 'D', 'E'}; for (int i = 0; i < alpha.Length; i++) { dt.Columns.Add(alpha[i].ToString()); } for (int i = 0; i < 1000; i++) { DataRow dr = dt.NewRow(); dr[0] = i + 1; dt.Rows.Add(dr); } GridView1.BorderColor = System.Drawing.Color.FromArgb(0, 0, 0); GridView1.DataSource = dt; GridView1.DataBind(); }
modified on Saturday, June 6, 2009 3:56 PM
-
I made a simple gridview in asp.net using the code written below. Now I want to make it editable so that at run time user can enter some data. Also,I dont want to put a thing like "edit button" ,i.e a user can simply edit a cell as he does in an excel spreadsheet. Can anybody tell me which event make the gridview editable ( I am not using any database) ? If possible, please give some code to help me understand. protected void Page_Load(object sender, EventArgs e) { dt = new DataTable(); Char[] alpha = { '#', 'A', 'B', 'C', 'D', 'E'}; for (int i = 0; i < alpha.Length; i++) { dt.Columns.Add(alpha[i].ToString()); } for (int i = 0; i < 1000; i++) { DataRow dr = dt.NewRow(); dr[0] = i + 1; dt.Rows.Add(dr); } GridView1.BorderColor = System.Drawing.Color.FromArgb(0, 0, 0); GridView1.DataSource = dt; GridView1.DataBind(); }
modified on Saturday, June 6, 2009 3:56 PM
Create one gridview with all template field and set textbox for that template field when it displays the data it will display in textbox so that you can edit those field without click edit button. Then you can access those textbox value when you click on a button. Look at the following code to do so...
<asp:GridView ID="GridView1" runat="server" Style="z-index: 106; left: 93px; position: absolute;
top: 283px" Width="575px" EditIndex="1" AutoGenerateColumns="False">
<Columns>
asp:TemplateField
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server" MaxLength="3" Style="position: static" CssClass ="gv" text = '<%# Eval("slNo") %>'
AutoPostBack ="false" TabIndex ="0" Width="25px" Height ="15px" Visible ="true" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
asp:TemplateField
<ItemTemplate>
<asp:TextBox ID="txt2" runat="server" MaxLength="3" Style="position: static" CssClass ="gv" text = '<%# Eval("Name") %>'
AutoPostBack ="false" TabIndex ="0" Width="250px" Height ="15px" Visible ="true" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
asp:TemplateField
<ItemTemplate>
<asp:TextBox ID="txt3" runat="server" MaxLength="3" Style="position: static" CssClass ="gv" text = '<%# Eval("Address") %>'
AutoPostBack ="false" TabIndex ="0" Width="150px" Height ="15px" Visible ="true" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>Then Place the following code in the button click event
for (int i = 0; i
after this you can use that string value to store into database or do further process.
Manoranjan Sahoo
Vist My Blog : Manoranjan's Blog