speedbeeqs
asked on
Datagrid Custome Item
I need create a datagrid which have a column call Lock. That column view show as a list checkbox if value of column is 1 checkbox will show checked and 0 is unchecked.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I converted it to C# but it has some wrong:
public class ucMainUser : System.Web.UI.UserControl
{
WebClasses.WC_DB db = new WC_DB();
protected System.Web.UI.WebControls. DataGrid dgUser;
WebClasses.WC_HTTPContext context = new WC_HTTPContext();
DataTable dt = new DataTable();
private void Page_Load(object sender, System.EventArgs e)
{
TemplateColumn cols = new TemplateColumn();
cols.HeaderText = "Lock";
cols.ItemTemplate = new DynamicItemTemplate();
if (!Page.IsPostBack)
{
db.ConnectingString = ConfigurationSettings.AppS ettings["C onnectingS tring"];
dt = db.GetData("SELECT * FROM STREAM_USER");
dgUser.DataSource = dt;
dgUser.Columns.Add(cols);
dgUser.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.P age_Load);
}
#endregion
}
public class DynamicItemTemplate : System.Web.UI.ITemplate
{
public void InstantiateIn(Control container)
{
CheckBox oCheckBox = new CheckBox();
oCheckBox.DataBinding += new EventHandler(this.BindChec kBox);
container.Controls.Add(oCh eckBox);
}
public void BindCheckBox(object sender,System.EventArgs e)
{
CheckBox oCheckBox = (CheckBox)sender;
DataGridItem container = (DataGridItem)oCheckBox.Na mingContai ner;
if (container.["IUSER_LOCKED" ].GetType( ).ToString ()=="Syste m.DBNull") <---Wrong here
{
oCheckBox.Checked = false;
}
else
oCheckBox.Checked = (bool)container.DataSetInd ex["IUSER_ LOCKED"]; <--Wrong here
}
}
public class ucMainUser : System.Web.UI.UserControl
{
WebClasses.WC_DB db = new WC_DB();
protected System.Web.UI.WebControls.
WebClasses.WC_HTTPContext context = new WC_HTTPContext();
DataTable dt = new DataTable();
private void Page_Load(object sender, System.EventArgs e)
{
TemplateColumn cols = new TemplateColumn();
cols.HeaderText = "Lock";
cols.ItemTemplate = new DynamicItemTemplate();
if (!Page.IsPostBack)
{
db.ConnectingString = ConfigurationSettings.AppS
dt = db.GetData("SELECT * FROM STREAM_USER");
dgUser.DataSource = dt;
dgUser.Columns.Add(cols);
dgUser.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.P
}
#endregion
}
public class DynamicItemTemplate : System.Web.UI.ITemplate
{
public void InstantiateIn(Control container)
{
CheckBox oCheckBox = new CheckBox();
oCheckBox.DataBinding += new EventHandler(this.BindChec
container.Controls.Add(oCh
}
public void BindCheckBox(object sender,System.EventArgs e)
{
CheckBox oCheckBox = (CheckBox)sender;
DataGridItem container = (DataGridItem)oCheckBox.Na
if (container.["IUSER_LOCKED"
{
oCheckBox.Checked = false;
}
else
oCheckBox.Checked = (bool)container.DataSetInd
}
}
ASKER
nobody help me???!
I'm related in VB, :-(, but let's try DBNull.value.
Or container.["IUSER_LOCKED"] = System.DBNull.value 'or = ""
ASKER
Toi nghi ban la nguoi VietNam nen toi ghi tieng Viet cho de~:
VB.net thi` la`: container.DataItem["IUSER_ LOCKED"].D ataType.To String() = "System.DBNull.value"
nhung chuyen sang C# thi khong duoc. Ko biet chuyen nhu the nao`.
---
If you're not a Vietnamese:
VB.net is: container.DataItem["IUSER_ LOCKED"].D ataType.To String() = "System.DBNull.value"
But when i convert to C# it will be wrong. I don't understand
VB.net thi` la`: container.DataItem["IUSER_
nhung chuyen sang C# thi khong duoc. Ko biet chuyen nhu the nao`.
---
If you're not a Vietnamese:
VB.net is: container.DataItem["IUSER_
But when i convert to C# it will be wrong. I don't understand
ASKER
oh sorry I type wrong:
VB.net is: container.DataItem("IUSER_ LOCKED").D ataType.To String() = "System.DBNull.value"
But when i convert to C# it will be wrong. I don't understand
VB.net is: container.DataItem("IUSER_
But when i convert to C# it will be wrong. I don't understand
Hi, I'm Vietnamese, but to make it fair to the experts here, let's use English.
No, I mean 2 ways to check it
1. Container.Dataitem["ISDER_ LOCKED"]= System.DBNull.value
2. Container.Dataitem["ISDER_ LOCKED"].G etype.ToSt ring = "System.DBNull"
Give it a try, buddy.
No, I mean 2 ways to check it
1. Container.Dataitem["ISDER_
2. Container.Dataitem["ISDER_
Give it a try, buddy.
Must change it like this:
if (((DataRowView)container.D ataItem)[" IUSER_LOCK ED"] == System.DBNull.Value)
{
oCheckBox.Checked = false;
}
else
{
oCheckBox.Checked = Convert.ToBoolean(((DataRo wView)cont ainer.Data Item)["IUS ER_LOCKED" ]);
}
if (((DataRowView)container.D
{
oCheckBox.Checked = false;
}
else
{
oCheckBox.Checked = Convert.ToBoolean(((DataRo
}
ASKER
Thanks all experts
Happry programming.
Speedbeeqs : If there's something interesting, contact me at vinhthuy.nguyen@gmail.com
Speedbeeqs : If there's something interesting, contact me at vinhthuy.nguyen@gmail.com
ASKER