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.
speedbeeqsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinhthuy_nguyenCommented:
Hi, there are some ways to do that, this is one, pls check :
http://support.microsoft.com/kb/306227/EN-US/#3



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
speedbeeqsAuthor Commented:
I need C# code!
0
speedbeeqsAuthor Commented:
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.AppSettings["ConnectingString"];
                        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.Page_Load);

            }
            #endregion
      }
      public class DynamicItemTemplate : System.Web.UI.ITemplate
      {
            public void InstantiateIn(Control container)
            {
                  CheckBox oCheckBox = new CheckBox();
                  oCheckBox.DataBinding += new EventHandler(this.BindCheckBox);
                  container.Controls.Add(oCheckBox);
            }
            public void BindCheckBox(object sender,System.EventArgs e)
            {
                  CheckBox oCheckBox = (CheckBox)sender;
                  DataGridItem container = (DataGridItem)oCheckBox.NamingContainer;
      if (container.["IUSER_LOCKED"].GetType().ToString()=="System.DBNull")   <---Wrong here
                  {
                        oCheckBox.Checked = false;
                  }
                  else
      oCheckBox.Checked = (bool)container.DataSetIndex["IUSER_LOCKED"]; <--Wrong here
            }
                     }
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

speedbeeqsAuthor Commented:
nobody help me???!
0
vinhthuy_nguyenCommented:
I'm related in VB, :-(, but let's try DBNull.value.
0
vinhthuy_nguyenCommented:
Or container.["IUSER_LOCKED"] = System.DBNull.value 'or = ""
   
0
speedbeeqsAuthor Commented:
Toi nghi ban la nguoi VietNam nen toi ghi tieng Viet cho de~:
VB.net thi` la`: container.DataItem["IUSER_LOCKED"].DataType.ToString() = "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"].DataType.ToString() = "System.DBNull.value"
But when i convert to C# it will be wrong. I don't understand
0
speedbeeqsAuthor Commented:
oh sorry I type wrong:
VB.net is: container.DataItem("IUSER_LOCKED").DataType.ToString() = "System.DBNull.value"
But when i convert to C# it will be wrong. I don't understand
0
vinhthuy_nguyenCommented:
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"].Getype.ToString = "System.DBNull"
Give it a try, buddy.
0
manyspeedCommented:
Must change it like this:
                  if (((DataRowView)container.DataItem)["IUSER_LOCKED"] == System.DBNull.Value)
                  {
                        oCheckBox.Checked = false;
                  }
                  else
                  {
                        oCheckBox.Checked = Convert.ToBoolean(((DataRowView)container.DataItem)["IUSER_LOCKED"]);
                  }
0
speedbeeqsAuthor Commented:
Thanks all experts
0
vinhthuy_nguyenCommented:
Happry programming.
Speedbeeqs : If there's something interesting, contact me at vinhthuy.nguyen@gmail.com
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.