Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom Datagrid! Help!!!

Custom Datagrid! Help!!!

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dgap
    wrote on last edited by
    #1

    Hi guys, I have two checkboxes on my datagrid and I have an event that fires whenever the first checkbox is checked (code follows)... but I don't know how to figure out where (what index) the checkbox that fired the event is coming from!!! Please Help!!! private void cb_CheckedChanged(object sender, EventArgs e) { bool bIsChecked; CheckBox cbTemp = (CheckBox) sender; bIsChecked = cbTemp.Checked; if (bIsChecked && ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked) ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked = false; } Thanks in advance to anyone who helps me out!

    M 1 Reply Last reply
    0
    • D dgap

      Hi guys, I have two checkboxes on my datagrid and I have an event that fires whenever the first checkbox is checked (code follows)... but I don't know how to figure out where (what index) the checkbox that fired the event is coming from!!! Please Help!!! private void cb_CheckedChanged(object sender, EventArgs e) { bool bIsChecked; CheckBox cbTemp = (CheckBox) sender; bIsChecked = cbTemp.Checked; if (bIsChecked && ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked) ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked = false; } Thanks in advance to anyone who helps me out!

      M Offline
      M Offline
      MihirV
      wrote on last edited by
      #2

      hi just lookup this code and try it.. protected void ChkChanged(object s, EventArgs e) { int index = int.Parse(((CheckBox)s).Attributes["myIndex"]); Response.Write(index.ToString()); } private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)e.Item.FindControl("chk"); chk.Attributes.Add("myIndex", e.Item.ItemIndex.ToString()); } } Mihir...

      D 2 Replies Last reply
      0
      • M MihirV

        hi just lookup this code and try it.. protected void ChkChanged(object s, EventArgs e) { int index = int.Parse(((CheckBox)s).Attributes["myIndex"]); Response.Write(index.ToString()); } private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)e.Item.FindControl("chk"); chk.Attributes.Add("myIndex", e.Item.ItemIndex.ToString()); } } Mihir...

        D Offline
        D Offline
        dgap
        wrote on last edited by
        #3

        Mihir, Is "myIndex" a function that I write myself? by the way, thanks a lot for your reply! I really appreciate it...

        1 Reply Last reply
        0
        • M MihirV

          hi just lookup this code and try it.. protected void ChkChanged(object s, EventArgs e) { int index = int.Parse(((CheckBox)s).Attributes["myIndex"]); Response.Write(index.ToString()); } private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)e.Item.FindControl("chk"); chk.Attributes.Add("myIndex", e.Item.ItemIndex.ToString()); } } Mihir...

          D Offline
          D Offline
          dgap
          wrote on last edited by
          #4

          When I get to this line, CheckBox chk = (CheckBox)e.Item.FindControl("chk"); I get the error "Object reference not set to an instance of an object" Any ideas of what I may be doing wrong?

          M 1 Reply Last reply
          0
          • D dgap

            When I get to this line, CheckBox chk = (CheckBox)e.Item.FindControl("chk"); I get the error "Object reference not set to an instance of an object" Any ideas of what I may be doing wrong?

            M Offline
            M Offline
            MihirV
            wrote on last edited by
            #5

            hi "myIndex" will be rendered as TAG Attribute like follow ------------------------------------- error you get coz you dont have checkbox in alternative item do one thing, remove e.Item.ItemType == AlternativeItem from if condition hope may be useful to you... Mihir...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups