Unable to add PageIndex to the GridViewTemplate : ITemplate javascript function - c#

I've got dynamically created GridView in code behind. Now during actual DataBinding event I've got a JavaScript function in place that is saving edited cell and its value. This all works fine without a pager, now when I add pager to GW I need to add to JS function the Page Index so I can calculate later which row/cell it actually was that got changed.
// Databind an edit box in the grid
void edt_DataBinding(object sender, EventArgs e)
{
DropDownList txtData = (DropDownList)sender;
GridViewRow container = (GridViewRow)txtData.NamingContainer;
object dataValue = DataBinder.Eval(container.DataItem, _columnName);
txtData.Attributes.Add("onchange", "sav(" + container.RowIndex.ToString() + "," + _columnName + ",this.value)");
if (dataValue != DBNull.Value)
{
txtData.SelectedItem.Text = dataValue.ToString();
txtData.BackColor = Color.LightGreen;
}
}
I tried to add "grdMain.PageIndex" to the JS but the following error occurs: "Cannot access the non-static member of outer type....
txtData.Attributes.Add("onchange", "sav(" + grdMain.PageIndex + container.RowIndex.ToString() + "," + _columnName + ",this.value)");
Any intelligent workaround?
More code:
public class GridViewTemplate : ITemplate
{
private ListItemType _templateType;
private string _columnName;
private string _col;
private string _dataType;
private bool _isLabel;
private bool _isCategory;
private string _types;
private IQueryable _role;
public GridViewTemplate(ListItemType type, string colname, string col, string DataType, bool isLabel, bool isCategory, string types, IQueryable role)
{
_templateType = type;
_columnName = colname;
_dataType = DataType;
_col = col;
_isLabel = isLabel;
_isCategory = isCategory;
_types = types;
_role = role;
}
void ITemplate.InstantiateIn(System.Web.UI.Control container)
{
Label lbl = new Label();
switch (_types)
{....
}
}
void lbl_DataBinding(object sender, EventArgs e)
{
Label lbl = (Label)sender;
GridViewRow container = (GridViewRow)lbl.NamingContainer;
object dataValue = DataBinder.Eval(container.DataItem, _columnName);
if (dataValue != DBNull.Value)
{
lbl.Text = dataValue.ToString();
}
}
// Databind an edit box in the grid
void edt_DataBinding(object sender, EventArgs e)
{....
}
}
Button Click:
.....
TemplateField tfUsers = new TemplateField();
grdMain.Columns.Add(tfUsers);
tfUsers.ItemTemplate = new GridViewTemplate(ListItemType.Item, "Name", "0", "String", true, false, "resource", lame);
tfUsers.HeaderTemplate = new GridViewTemplate(ListItemType.Header, "Resource", "0", "String", true, false, "resource", lame);
_dtEntry.Columns.Add("Name");
......

i dont know your full code so i am guessing here...
have you tried in ItemDataBound?
something like this...
protected void grdMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
txtData.Attributes.Add("onchange", "sav(" + grdMain.PageIndex + container.RowIndex.ToString() + "," + _columnName + ",this.value)");
}
}

Related

Telerik: Unable to get Selected Value of Dropdownlist added to Autogenerated Radgrid

I added a dropdownlist to an auto-generated RadGrid in code behind, however, I am unable to get the selected value when the row is updated. I add the dropdownlist as follows:
protected void grdAssetImport_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
TextBox txt = (TextBox)edit["AssetTypeName"].Controls[0];
txt.Visible = false;
DropDownList rddl = new DropDownList();
PortalView.LookupListBO list = LookupListBA.LookupList_GetByKey(DB_Context, "SITE_ASSETTYPE_LIST", UtilityBA.IsActiveChoice.Active);
List<PortalView.LookupListItemBO> oList = LookupListBA.LookupListItem_GetList_ByLookupListId(DB_Context, list.LookupListId, (Guid)Current.Employee.SiteId);
var AssetList = oList.Select(l => new { AssetTypeName = l.Name });
rddl.ID = "ddlAssetTypeName";
rddl.AutoPostBack = false;
rddl.DataSource = AssetList;
rddl.DataTextField = "AssetTypeName";
rddl.DataValueField = "AssetTypeName";
rddl.DataBind();
edit["AssetTypeName"].Controls.Add(rddl);
}
}
I tried retrieving the selected value in the UpdateCommand, but have been unsuccessful:
protected void grdAssetImport_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
GridEditableItem editableItem = e.Item as GridEditableItem;
DropDownList ddl = editableItem.FindControl("ddlAssetTypeName") as DropDownList;
if(ddl != null)
{
string assetType = ddl.SelectedValue;
}
DropDownList ddl2 = editableItem["AssetTypeName"].Controls[0] as DropDownList;
if(ddl2 != null)
{
string assetType = ddl.SelectedValue;
}
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
string editorText = "unknown";
object editorValue = null;
if (editor is GridTextColumnEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
}
if (editor is GridBoolColumnEditor)
{
editorText = (editor as GridBoolColumnEditor).Value.ToString();
editorValue = (editor as GridBoolColumnEditor).Value;
}
if (editor is GridDropDownColumnEditor)
{
editorText = (editor as GridDropDownColumnEditor).SelectedText + "; " +
(editor as GridDropDownColumnEditor).SelectedValue;
editorValue = (editor as GridDropDownColumnEditor).SelectedValue;
}
try
{
DataRow[] changedRows = this.AssetGridDataSource.Select("Id = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Id"].ToString());
changedRows[0][column.UniqueName] = editorValue;
this.AssetGridDataSource.AcceptChanges();
GetSearchColumns();
}
catch (Exception ex)
{
// Label1.Text = "<strong>Unable to set value of column '" + column.UniqueName + "'</strong> - " + ex.Message;
e.Canceled = true;
break;
}
}
}
}
}
It never finds the dropdownlist, and always only sees the GridTextColumnEditor of the column so the only value I get is the original value before edit mode.
Any assistance is greatly appreciated!
Items do not bind every time and so the ItemDataBound event fires less times than you think. To add a control every time an item is created, you would need to use the ItemCreated event instead.
I've tested the following and works.
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
GridEditableItem edititem = e.Item as GridEditableItem;
DropDownList rddl = new DropDownList();
edititem["AssetTypeName"].Controls[0].Visible = false;
rddl.ID = "ddlAssetTypeName";
rddl.AutoPostBack = false;
rddl.DataSource = Enumerable.Range(1, 3).Select(x => "Item" + x).ToList();
rddl.DataBind();
edititem["AssetTypeName"].Controls.Add(rddl);
}
}
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
DropDownList ddl = editedItem["AssetTypeName"].FindControl("ddlAssetTypeName") as DropDownList;
string selectedValue = ddl.SelectedValue;
}

Keep State of Gridview

I have a gridview and I'm trying to keep the state of. Currently I have it where the user can edit inline( from within the gridview). Regularly I got this working:
protected void GridViewTower_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
GridViewTower.EditIndex = e.NewEditIndex;
//Bind/Re-LoadData data to the GridView control.
LoadData();
Populate();
}
protected void GridViewTower_CancelEditRow(object sender, GridViewCancelEditEventArgs e)
{
//Reset the edit index.
GridViewTower.EditIndex = -1;
//Bind/Re-LoadData data to the GridView control.
LoadData();
Populate();
}
Problem is, I have 3 other features such sorting, dropdown that filters gridview, and a button search which also filters the girdview. When inline editing within any 3 of those modes, I can't control the state in which the gridview is in. Inside my gridview tag, I have both EnableViewState and ViewStateMode set to true.
How can I keep the state of the gridview within these modes?
public void LoadData()
{
if (Session["GridView"] != null)
{
GridViewTower.DataSource = Session["GridView"];
GridViewTower.DataBind();
//Response.Redirect("TowerManagement.aspx"); //
//Session["GridView"] = null;
}
else
{
WISSModel.WISSEntities context = new WISSModel.WISSEntities();
var tower = (from t in context.Towers
where t.isDeleted == false
select new
{
t.TowerId,
t.TowerName,
RangeName = t.Range.RangeName
}).ToList();
GridViewTower.DataSource = tower;
GridViewTower.DataBind();
ViewState["Sort"] = 0;
}
}
protected void Gridview_Sort(object sender, GridViewSortEventArgs e)
{
WISSModel.WISSEntities context = new WISSModel.WISSEntities();
var towers = (from t in context.Towers
where t.isDeleted == false
select new
{
t.TowerId,
t.TowerName,
rangeName = t.Range.RangeName
}).ToList();
DataTable gridviewTable = towers.CopyToDataTable();
gridviewTable.DefaultView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
GridViewTower.DataSource = gridviewTable;
GridViewTower.DataBind();
Session["GridView"] = GridViewTower.DataSource;
}
You don't need to store whole table in the Session or ViewState. Just store values of SortExpression, SortOrder etc. Here's an example how you can do it.
In my code I have added two private properties to store sortorder and sortexpression:
private string SortOrder
{
get
{
// Toggle order after sorting
string _order = "ASC";//Default
if( ViewState["SortOrder"] != null && ViewState["SortOrder"].ToString() =="DESC")
{
_order = "DESC";
ViewState["SortOrder"] = "ASC";
}
else
{
ViewState["SortOrder"] = "DESC";
}
return _order;
}
set
{
string _order = value.ToLower() == "descending"? "DESC" : "ASC";
ViewState["SortOrder"] = _order;
}
}
private string SortExpression
{
get
{
return ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : "";
}
set
{
ViewState["SortExpression"] = value;
}
}
I have changed your GridView_Sort method to store the sort expression and sort order in newly added properties and called LoadData() method:
protected void Gridview_Sort(object sender, GridViewSortEventArgs e)
{
SortExpression = e.SortExpression;
//Disabled sort direction to enable toggling
//SortOrder = e.SortDirection.ToString();
LoadData();
}
The LoadData() method will be called from many places, whenever we want to load data into GridView. So I have changed it to this:
public void LoadData()
{
WISSModel.WISSEntities context = new WISSModel.WISSEntities();
var towers = (from t in context.Towers
where t.isDeleted == false
select new
{
t.TowerId,
t.TowerName,
rangeName = t.Range.RangeName
}).ToList();
DataTable gridviewTable = new DataTable();
gridviewTable.Columns.Add("TowerId");
gridviewTable.Columns.Add("TowerName");
gridviewTable.Columns.Add("rangeName");
foreach (var t in towers)
{
gridviewTable.Rows.Add(new object[] { t.TowerId, t.TowerName, t.rangeName });
}
if (!String.IsNullOrEmpty(SortExpression))
{
gridviewTable.DefaultView.Sort = String.Format("{0} {1}", SortExpression, SortOrder);
gridviewTable = gridviewTable.DefaultView.ToTable();
}
GridViewTower.DataSource = gridviewTable;
GridViewTower.DataBind();
}
Initially I call the LoadData() method in Page_Load() :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
You can download the test project here.

Using PostBackUrl, Getting PreviousPage.Control()

I'm using PostBackUrl to post my control from a "firstwebpage.aspx" to a "secondwebpage.aspx" so that I would be able to generate some configuration files.
I do understand that I can make use of PreviousPage.FindControl("myControlId") method in my secondwebpage.aspx to get my control from "firstwebpage.aspx"and hence grab my data and it worked.
However, it seems that this method does not work on controls which I generated programmically during runtime while populating them in a table in my firstwebpage.aspx.
I also tried using this function Response.Write("--" + Request["TextBox1"].ToString() + "--");
And although this statement do printout the text in the textfield on TextBox1, it only return me the string value of textbox1. I am unable to cast it to a textbox control in the following format too
TextBox temptextBox = (TextBox)Request["TextBox1"];
My question is, how can I actually access the control which i generated programmically in "firstwebpage.aspx" on "secondwebpage.aspx"?
Please advice!
thanks alot!
//my panel and button in aspx
<asp:Panel ID="Panel2" runat="server"></asp:Panel>
<asp:Button ID="Button1" runat="server" Text="Generate Xml" PostBackUrl="~/WebForm2.aspx" onclick="Button1_Click" />
//this is my function to insert a line into the panel
public void createfilerow(string b, string path, bool x86check, bool x86enable, bool x64check, bool x64enable)
{
Label blank4 = new Label();
blank4.ID = "blank4";
blank4.Text = "";
Panel2.Controls.Add(blank4);
CheckBox c = new CheckBox();
c.Text = b.Replace(path, "");
c.Checked = true;
c.ID = "1a";
Panel2.Controls.Add(c);
CheckBox d = new CheckBox();
d.Checked = x86check;
d.Enabled = x86enable;
d.ID = "1b";
Panel2.Controls.Add(d);
CheckBox e = new CheckBox();
e.Checked = x64check;
e.Enabled = x64enable;
e.ID = "1c";
Panel2.Controls.Add(e);
}
//my virtual path in WebForm2.aspx
<%# PreviousPageType VirtualPath="~/WebForm1.aspx" %>
//my pageload handler
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
CheckBox tempCheckbox = (CheckBox)Page.PreviousPage.FindControl("1a");
Button1.Text = tempCheckbox.Text;
}
}
//handler which will populate the panel upon clicking
protected void Button7_Click(object sender, EventArgs e)
{
//get foldername
if (!Directory.Exists(#"myfilepath" + TextBox2.Text))
{
//folder does not exist
//do required actions
return;
}
string[] x86files = null;
string[] x64files = null;
string[] x86filespath = null;
string[] x64filespath = null;
ArrayList common = new ArrayList();
if (Directory.Exists(#"myfilepath" + TextBox2.Text + "\\x86"))
x86files = Directory.GetFileSystemEntries("myfilepath" + TextBox2.Text + "\\x86");
if (Directory.Exists(#"myfilepath" + TextBox2.Text + "\\x64"))
x64files = Directory.GetFileSystemEntries("myfilepath" + TextBox2.Text + "\\x64");
//some codes to convert x64files and x86files to string[]
//The header for Panel, 4 column
Label FL = new Label();
FL.ID = "flavourid";
FL.Text = "Flavour";
Panel2.Controls.Add(FL);
Label filetext = new Label();
filetext.ID = "filenamelabel";
filetext.Text = "File(s)";
Panel2.Controls.Add(filetext);
Label label86 = new Label();
label86.ID = "label86";
label86.Text = "x86";
Panel2.Controls.Add(label86);
Label label64 = new Label();
label64.ID = "label64";
label64.Text = "x64";
Panel2.Controls.Add(label64);
//a for loop determine number of times codes have to be run
for (int a = 0; a < num; a++)
{
ArrayList location = new ArrayList();
if (//this iteration had to be run)
{
string path = null;
switch (//id of this iteration)
{
case id:
path = some network address
}
//check the current version of iternation
string version = //version type;
//get the platform of the version
string platform = //platform
if (curent version = certain type)
{
//do what is required.
//build a list
}
else
{
//normal routine
//do what is required
//build a list
}
//populating the panel with data from list
createflavourheader(a);
//create dynamic checkboxes according to the list
foreach(string s in list)
//createrow parameter is by version type and platform
createfilerow(readin, path, true, true, false, false);
}
}
}
form1.Controls.Add(Panel2);
}
Sorry can't show you the full code as it is long and I believe it should be confidential even though i wrote them all
Yes you can access, Below is an example
// On Page1.aspx I have a button for postback
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
PostBackUrl="~/Page2.aspx" />
// Page1.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
TextBox t = new TextBox(); // created a TextBox
t.ID = "myTextBox"; // assigned an ID
form1.Controls.Add(t); // Add to form
}
Now on the second page I will get the value of TextBox as
// Page2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox t = (TextBox) PreviousPage.FindControl("myTextBox");
string mytboxvalue = t.Text;
}
// OR
string myTextBoxValue = Request.Form["myTextBox"];
}
Updated Answer:
Panel myPanel = new Panel();
myPanel.ID = "myPanel";
TextBox t = new TextBox();
t.ID = "myTextBox";
myPanel.Controls.Add(t);
TextBox t1 = new TextBox();
t1.ID = "myTextBox1";
myPanel.Controls.Add(t1);
// Add all your child controls to your panel and at the end add your panel to your form
form1.Controls.Add(myPanel);
// on the processing page you can get the values as
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox t = (TextBox) PreviousPage.FindControl("myTextBox");
string mytboxvalue = t.Text;
}
string myTextBoxValue = Request.Form["myTextBox1"];
}
I also tried using this function Response.Write("--" +
Request["TextBox1"].ToString() + "--"); And although this statement do
printout the text in the textfield on TextBox1, it only return me the
string value of textbox1. I am unable to cast it to a textbox control
in the following format too
TextBox temptextBox = (TextBox)Request["TextBox1"];
Hi lw,
I think you may try passing the type of control (e.g. 'tb') together with the content and creating a new object (e.g. TextBox) and assign it to templtexBox object.
My 20 cents.
Andy

ICallbackEventHandler, RaiseCallbackEvent not firing

I have the following Javascript:
function processText(n)
{
CallServer("1" + n.id + "&" + n.value, "");
}
function ReceiveServerData(arg, context)
{
alert(arg);
}
With this for my code-behind:
protected void Page_Load(object sender, EventArgs e)
{
ClientScriptManager cm = Page.ClientScript;
String cbRef = cm.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackscript = "function CallServer(arg, context) {" + cbRef + "; }";
cm.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackscript, true);
if (Request.QueryString["stationID"] != null)
{
isIndividual = true;
stationID = Request.QueryString["stationID"];
EncodeDecode objServers = new EncodeDecode(HttpContext.Current.Server.MapPath("~/App_Data/"));
if (!IsPostBack)
{
List<IServerConfig> serverConfig = objServers.GetServerConfiguration(stationID);
Session["ServerConfig"] = serverConfig;
Session["dctPropertyControls"] = new Dictionary<string, PropertyObj>();
}
BindDynamicControls(Session["ServerConfig"] as List<IServerConfig>);
}
}
public void RaiseCallbackEvent(String eventArgument)
{
int iTyped = int.Parse(eventArgument.Substring(0, 1).ToString());
if (iTyped != 0) //Process Text Fields
{
string controlName = eventArgument.Substring(1, eventArgument.IndexOf("&")).ToString();
string controlValue = eventArgument.Substring(eventArgument.IndexOf("&")).ToString();
//Txtid += -1;
Dictionary<string, PropertyObj> dctPropertyObj = Session["dctPropertyControls"] as Dictionary<string, PropertyObj>;
PropertyObj propertyObj = dctPropertyObj[controlName];
propertyObj.property.SetValue(propertyObj.owner, controlValue, null);
this.sGetData = "Done";
}
}
public String GetCallbackResult()
{
return this.sGetData;
}
processText gets fired and works, however RaiseCallbackEvent never fires. Any ideas?
Apparently, any sort of validation error will cause this, though the page will never tell you about it. In my case, I had two datalists on the page with the same id. I had to debug the javascript and read the xmlRequest to see the error.
Sorry if replying late but may help others..
ValidationRequest="false" at .aspx page may sort out this unidentified problem.

Sorting gridview embedded in user control

I have created an asp.net usercontrol that should list users in a number of applications. For that purpose, the control renders a repeater (foreach application) which in turn renders a gridview (with users for that application).
The control renders fine, except the fact that columns in the gridview are not sortable. Nothing happens (no postback) when clicking the headers. Apparently, no JavaScript is rendered to perform the postback when clicking the header.
This is the code:
[DefaultProperty("Text")]
[ToolboxData("<{0}:UserList runat=\"server\"></{0}:UserList>")]
public class UserList : WebControl
{
#region Variables
private Repeater list;
private Literal heading;
#endregion
#region Events
#endregion
#region Constructors
public UserList() : base()
{
// Default settings for list control.
list = new Repeater() { ID = "userList" };
heading = new Literal() { ID = "userListHeading" };
}
#endregion
#region Control event handlers
protected override void OnInit(EventArgs e)
{
var css = "<link href=\"" + Page.ClientScript.GetWebResourceUrl(typeof(UserList), "Web.UI.Resources.CSS.UserList.css") + "\" type=\"text/css\" rel=\"stylesheet\" />";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UserListCss", css, false);
base.OnInit(e);
}
public override void RenderControl(HtmlTextWriter writer)
{
heading.RenderControl(writer);
list.RenderControl(writer);
base.RenderControl(writer);
}
protected override void OnLoad(EventArgs e)
{
// set properties
list.ItemTemplate = new ListTemplate();
// attach event handlers
list.ItemDataBound += new RepeaterItemEventHandler(OnList_ItemDataBound);
// bind data
var allRoles = AdvancedRoleProvider.Instance.GetAllRoles();
String appName = (Roles.ApplicationName.Equals("*") ? " alle applikationer" : Roles.ApplicationName);
heading.Text = String.Format("<h2>{0}</h2>", "Brugere i " + appName);
if (allRoles.Count == 0)
{
heading.Text += "Der kunne ikke findes nogen brugere.";
}
else
{
list.DataSource = allRoles;
list.DataBind();
}
base.OnLoad(e);
}
#endregion
#region List control event handlers
protected void OnList_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
KeyValuePair<String, IList<String>> data = (KeyValuePair<String, IList<String>>)e.Item.DataItem;
Literal litApplication = (Literal)e.Item.FindControl("litApplication");
litApplication.Text = String.Format(litApplication.Text, data.Key);
GridView gvUsers = (GridView)e.Item.FindControl("gvUsers");
gvUsers.RowDataBound += new GridViewRowEventHandler(OnGridViewUsers_RowDataBound);
gvUsers.Sorting += new GridViewSortEventHandler(OnGridViewUsers_Sorting);
gvUsers.DataSource = AdvancedRoleProvider.Instance.GetApplicationUsers(data.Key);
gvUsers.DataBind();
}
}
#endregion
void OnGridViewUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
void OnGridViewUsers_Sorting(object sender, GridViewSortEventArgs e)
{
// TODO: Impl. sorting logic
}
#region List layout template
/// <summary>
/// Layout template class for the repeater control.
/// </summary>
public class ListTemplate : ITemplate
{
#region Constructors
public ListTemplate()
{
}
#endregion
#region Public methods
public void InstantiateIn(Control container)
{
GridView gvUsers;
gvUsers = new GridView() { ID = "gvUsers", AutoGenerateColumns = false, AllowSorting = true };
BoundField userField = new BoundField() { HeaderText = "Bruger", DataField = "UserName", SortExpression = "UserName" };
userField.HeaderStyle.CssClass = userField.ItemStyle.CssClass = "userName";
BoundField fullNameField = new BoundField() { HeaderText = "Navn", DataField = "FullName", SortExpression = "FullName" };
fullNameField.HeaderStyle.CssClass = userField.ItemStyle.CssClass = "userName";
BoundField roleField = new BoundField() { HeaderText = "Rolle", DataField = "RoleName", SortExpression = "RoleName" };
roleField.HeaderStyle.CssClass = roleField.ItemStyle.CssClass = "roleName";
BoundField adField = new BoundField() { HeaderText = "AD Gruppe", DataField = "ADGroupName", SortExpression = "ADGroupName" };
adField.HeaderStyle.CssClass = adField.ItemStyle.CssClass = "adGroupName";
gvUsers.Columns.Add(userField);
gvUsers.Columns.Add(fullNameField);
gvUsers.Columns.Add(roleField);
gvUsers.Columns.Add(adField);
container.Controls.Add(new LiteralControl("<div id=\"userList\">"));
container.Controls.Add(new Literal() { ID = "litApplication", Text="<h3>{0}</h3>" });
container.Controls.Add(gvUsers);
container.Controls.Add(new LiteralControl("</div>"));
}
#endregion
#region Event handlers
#endregion
#region Properties
#endregion
}
#endregion
}
Any help would be greatly appreciated.
I don't know if this will work or not, but you may want try adding the grid through the designer/html. Also, you may want to add the handler at the html side as well instead of the OnList_ItemDataBound. Hope this helps.
<asp:GridView ID="gvUsers" runat="server" AllowSorting="True" onsorting="OnGridViewUsers_Sorting">

Categories

Resources