Forum: ASP.NET |
Thema:
Re: TextBox Style ändern in Datagrid |
Von:
Tobi Ulm (
09.12.2005 16:59) |
Hi ?,
so klappts
<code>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApp_CS
{
/// <summary>
/// Zusammenfassung für WebForm4.
/// </summary>
public class WebForm4 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WebApp_CS.DataSet1 dataSet11;
private bool mEdit = false;
private void Page_Load(object sender, System.EventArgs e)
{
// Hier Benutzercode zur Seiteninitialisierung einfügen
if ( ! Page.IsPostBack ){
this.BindData();
}
}
private void BindData(){
this.sqlDataAdapter1.Fill(this.dataSet11.Customers);
this.DataGrid1.DataBind();
}
#region Vom Web Form-Designer generierter Code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dataSet11 = new WebApp_CS.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"),
new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"),
new System.Data.Common.DataColumnMapping("ContactName", "ContactName"),
new System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"),
new System.Data.Common.DataColumnMapping("Address", "Address"),
new System.Data.Common.DataColumnMapping("City", "City"),
new System.Data.Common.DataColumnMapping("Region", "Region"),
new System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"),
new System.Data.Common.DataColumnMapping("Country", "Country"),
new System.Data.Common.DataColumnMapping("Phone", "Phone"),
new System.Data.Common.DataColumnMapping("Fax", "Fax")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," +
" PostalCode, Country, Phone, Fax FROM Customers";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"XP-TOBI-2\";packet size=4096;integrated security=SSPI;data source=" +
"\"(local)\\dev2005\";persist security info=False;initial catalog=Northwind";
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("de-DE");
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
}
#endregion
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
this.mEdit = true;
this.BindData();
Response.Write(e.Item.Cells.Count.ToString());
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
if ( this.mEdit ) {
foreach (TableCell c in e.Item.Cells){
if (c.Controls.Count > 0 ){
for (int i = 0; i < c.Controls.Count; i++){
if ( c.Controls[i].GetType().Equals(typeof(TextBox)) ) {
TextBox tmpBox = (TextBox)c.Controls[i];
tmpBox.CssClass = "Sepp";
}
}
}
}
}
}
}
}
</code>
cu
Tobi
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!