Announcement

Collapse
No announcement yet.

GridView RowUpdating Spaltenüberschrift auslesen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • GridView RowUpdating Spaltenüberschrift auslesen

    Hallo,

    ich habe ein Griedview das an eine per Code erstellte Tabelle gebunden ist.
    Die Spalten dieser Tabelle sind erst zur Laufzeit bekannt und enhalten boolean Werte.
    Das Griedview erzeugt daher die Spalten automatisch.

    Im RowUpdating möchte ich nun auslesen welche Spalten haben sich geändert und wie lautet die Spaltenüberschrift zu dem geänderten Wert.

    Hat da wer eine Idee?

    Danke
    Bernhard

    Code:
    public partial class EK_Admin_permission : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!this.IsPostBack)
    {
    BindData();
    }

    }

    private DataTable CreateDataTableA()
    {
    DataTable aTable = new DataTable("A");
    DataColumn dtCol;
    DataRow dtRow;
    // Create ID column and add to the DataTable.
    dtCol = new DataColumn();
    dtCol.DataType = System.Type.GetType("System.Int32");
    dtCol.ColumnName = "ID";
    dtCol.AutoIncrement = true;
    dtCol.Caption = "ID";
    dtCol.ReadOnly = true;
    dtCol.Unique = true;

    // Add the column to the DataColumnCollection.
    aTable.Columns.Add(dtCol);

    // Create Rolle column and add to the table
    dtCol = new DataColumn();
    dtCol.DataType = System.Type.GetType("System.String");
    dtCol.ColumnName = "User";
    dtCol.AutoIncrement = false;
    dtCol.Caption = "User";
    dtCol.ReadOnly = true;
    dtCol.Unique = true;

    // Add the column to the DataColumnCollection.
    aTable.Columns.Add(dtCol);

    string[] rollen = Roles.GetAllRoles();
    foreach (string rolle in rollen)
    {
    dtCol = new DataColumn();
    dtCol.DataType = System.Type.GetType("System.Boolean");
    dtCol.ColumnName = rolle;
    dtCol.AutoIncrement = false;
    dtCol.Caption = rolle;
    dtCol.ReadOnly = false;
    dtCol.Unique = false;
    aTable.Columns.Add(dtCol);
    }

    MembershipUserCollection users = Membership.GetAllUsers();
    foreach (MembershipUser myuser in users)
    {
    //userinfo myuserinfo = new userinfo(myuser.UserName);
    dtRow = aTable.NewRow();
    dtRow["User"] = myuser.UserName;// +" " + myuserinfo.Name;

    foreach (DataColumn myCol in aTable.Columns)
    {
    if (myCol.ColumnName != "ID")
    {
    if (myCol.ColumnName != "User")
    {
    dtRow[myCol.ColumnName] = Roles.IsUserInRole(myuser.UserName , myCol.Caption);

    }
    }
    }

    aTable.Rows.Add(dtRow);
    }

    return aTable;
    }

    private void BindData()
    {
    if (Session["EK_Admin_permisson"] == null)
    {
    Session["EK_Admin_permisson"] = CreateDataTableA();
    string[] keynames = new string[2] { "ID","User" };
    GridView1.DataKeyNames = keynames;
    }

    GridView1.DataSource = (DataTable) Session["EK_Admin_permisson"];
    GridView1.DataBind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
    GridView1.EditIndex = e.NewEditIndex;
    BindData();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    string myuser = GridView1.DataKeys[e.RowIndex].Values[1].ToString();


    GridView1.EditIndex = -1;
    BindData();

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
    GridView1.EditIndex = -1;
    BindData();
    }
    protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }
    }
Working...
X