Να γραφεί σχετικό άρθρο για τα gridview edit mode
#region code for GridView Deleted
/*
grditems.AutoGenerateColumns = false;
BoundField field1, field2;
field1 = new BoundField();
field2 = new BoundField();
//field3 = new BoundField();
field1.HeaderText="Κωδ.Λίστας";
field1.DataField="ListID";
field2.HeaderText="Όν.Λίστας";
field2.DataField="ListName";
//field3.HeaderText = "Τελ.Αριθμός";
// field3.DataField = "LastNumber";
// field3.ReadOnly = false;
GridViewTemplate field3 = new GridViewTemplate(DataControlRowType.DataRow, "LastNumber");
TemplateField tc1 = new TemplateField();
field1.ReadOnly = true;
field2.ReadOnly = true;
grditems.Columns.Add(field1);
grditems.Columns.Add(field2);
tc1.ItemTemplate = field3;
grditems.Columns.Add(tc1);
// grditems.EditIndex = 1;
*/
ltral1.Text = "
";
ltral2.Text = "
";
btnNew.ID = "btnNew";
btnEdit.ID = "btnEdit";
btnDelete.ID = "btnDelete";
btnNew.Text = "Προσθήκη";
btnEdit.Text = "Edit";
btnDelete.Text = "Delete";
#endregion
#region Add Template Field in gridview
// TemplateField f = new TemplateField();
// f.ItemTemplate
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace prwbpt
{
// Create a template class to represent a dynamic template column.
public class GridViewTemplate:ITemplate
{
private DataControlRowType templateType;
private string columnName;
public GridViewTemplate(DataControlRowType type, string colname)
{
templateType = type;
columnName = colname;
}
public void InstantiateIn(System.Web.UI.Control container)
{
// Create the content for the different row types.
switch(templateType)
{
case DataControlRowType.Header:
// Create the controls to put in the header
// section and set their properties.
Literal lc = new Literal();
lc.Text = "
" + columnName + "";
// Add the controls to the Controls collection
// of the container.
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
// Create the controls to put in a data row
// section and set their properties.
// Label firstName = new Label();
// Label lastName = new Label();
// this is my code
TextBox txtLastNumber = new TextBox();
//Literal spacer = new Literal();
//spacer.Text = " ";
// To support data binding, register the event-handling methods
// to perform the data binding. Each control needs its own event
// handler.
txtLastNumber.DataBinding += new EventHandler(txtLastNumber_DataBinding);
//firstName.DataBinding += new EventHandler(this.FirstName_DataBinding);
//lastName.DataBinding += new EventHandler(this.LastName_DataBinding);
//// Add the controls to the Controls collection
//// of the container.
//container.Controls.Add(firstName);
//container.Controls.Add (spacer);
//container.Controls.Add(lastName);
container.Controls.Add(txtLastNumber);
break;
// Insert cases to create the content for the other
// row types, if desired.
default:
// Insert code to handle unexpected values.
break;
}
}
void txtLastNumber_DataBinding(object sender, EventArgs e)
{
TextBox l = (TextBox)sender;
GridViewRow row = (GridViewRow)l.NamingContainer;
l.Text = DataBinder.Eval(row.DataItem, columnName).ToString();
}
/*
private void FirstName_DataBinding(Object sender, EventArgs e)
{
// Get the Label control to bind the value. The Label control
// is contained in the object that raised the DataBinding
// event (the sender parameter).
Label l = (Label)sender;
// Get the GridViewRow object that contains the Label control.
GridViewRow row = (GridViewRow)l.NamingContainer;
// Get the field value from the GridViewRow object and
// assign it to the Text property of the Label control.
l.Text = DataBinder.Eval(row.DataItem, "au_fname").ToString();
}
private void LastName_DataBinding(Object sender, EventArgs e)
{
// Get the Label control to bind the value. The Label control
// is contained in the object that raised the DataBinding
// event (the sender parameter).
Label l = (Label)sender;
// Get the GridViewRow object that contains the Label control.
GridViewRow row = (GridViewRow)l.NamingContainer;
// Get the field value from the GridViewRow object and
// assign it to the Text property of the Label control.
l.Text = DataBinder.Eval(row.DataItem, "au_lname").ToString();
}
* */
}
}
Περισσότερα... »