[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

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.
0
speedbeeqs
Asked:
speedbeeqs
  • 6
  • 5
1 Solution
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now