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. gridview binding

gridview binding

Scheduled Pinned Locked Moved ASP.NET
databasewpfwcfquestion
3 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.
  • J Offline
    J Offline
    jainiraj
    wrote on last edited by
    #1

    I have add check box in a gridview in eachh row at run time.I have a delete button on page.If it is clicked then all checkbox are checed if true yhen delete corresponding row.I have use Template column for checkbox.and bind an id with it.On running page this id is also visible but i want to do invisible it.also how can i retrieve this id if checkbox is checked. here is code... protected void Page_Load(object sender, EventArgs e) { query="select brok.*,cust.FirstName+' '+cust.LastName as Name from brokermsgrecieved as brok,custdetails as cust where brok.BrokerId='"+Session["broker"]+"' and cust.CustId=brok.FromCustId"; dt = obj.select(query); GridView1.DataSource=dt; GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { CheckBox chk = new CheckBox(); e.Row.Cells[0].Controls.Add(chk); if (e.Row.Cells[1].Text == "True") { e.Row.BackColor = Color.Wheat; } if (e.Row.Cells[1].Text == "False") { e.Row.BackColor = Color.WhiteSmoke; } } protected void Button1_Click(object sender, EventArgs e) { GridView1.DataSource = dt; GridView1.DataBind(); Int16 count =(Int16) GridView1.Rows.Count; for (Int16 i = 1; i < count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].Controls[1]; if (chk.Checked.Equals(true)) { //query="Delete from brokermsgrecieved where " //GridView1.Rows[i].Cells[0].v query = "delete from brokermsgrecieved where MsgId='1'"; obj.insert(query); } } } here is code such that i bind id---- <Columns> asp:TemplateField <ItemTemplate> <%# Eval("MsgID") %> </ItemTemplate> </asp:TemplateField>

    T 1 Reply Last reply
    0
    • J jainiraj

      I have add check box in a gridview in eachh row at run time.I have a delete button on page.If it is clicked then all checkbox are checed if true yhen delete corresponding row.I have use Template column for checkbox.and bind an id with it.On running page this id is also visible but i want to do invisible it.also how can i retrieve this id if checkbox is checked. here is code... protected void Page_Load(object sender, EventArgs e) { query="select brok.*,cust.FirstName+' '+cust.LastName as Name from brokermsgrecieved as brok,custdetails as cust where brok.BrokerId='"+Session["broker"]+"' and cust.CustId=brok.FromCustId"; dt = obj.select(query); GridView1.DataSource=dt; GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { CheckBox chk = new CheckBox(); e.Row.Cells[0].Controls.Add(chk); if (e.Row.Cells[1].Text == "True") { e.Row.BackColor = Color.Wheat; } if (e.Row.Cells[1].Text == "False") { e.Row.BackColor = Color.WhiteSmoke; } } protected void Button1_Click(object sender, EventArgs e) { GridView1.DataSource = dt; GridView1.DataBind(); Int16 count =(Int16) GridView1.Rows.Count; for (Int16 i = 1; i < count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].Controls[1]; if (chk.Checked.Equals(true)) { //query="Delete from brokermsgrecieved where " //GridView1.Rows[i].Cells[0].v query = "delete from brokermsgrecieved where MsgId='1'"; obj.insert(query); } } } here is code such that i bind id---- <Columns> asp:TemplateField <ItemTemplate> <%# Eval("MsgID") %> </ItemTemplate> </asp:TemplateField>

      T Offline
      T Offline
      Tuwing Sabado
      wrote on last edited by
      #2

      use the HTML name attributre as place holder for other value. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { CheckBox chk = new CheckBox(); // use name html attribute as your ID placeholder chk.Attributes.Add("name", e.Row.Cells[100].Text); //e.Row.Cells[100].Text is my column id e.Row.Cells[0].Controls.Add(chk); } protected void Button1_Click(object sender, EventArgs e) { Int16 count = (Int16)GridView1.Rows.Count; for (Int16 i = 1; i < count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].Controls[1]; //get the value of attribute name. string id = CheckBox3.Attributes["name"]; } } happy coding..

      J 1 Reply Last reply
      0
      • T Tuwing Sabado

        use the HTML name attributre as place holder for other value. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { CheckBox chk = new CheckBox(); // use name html attribute as your ID placeholder chk.Attributes.Add("name", e.Row.Cells[100].Text); //e.Row.Cells[100].Text is my column id e.Row.Cells[0].Controls.Add(chk); } protected void Button1_Click(object sender, EventArgs e) { Int16 count = (Int16)GridView1.Rows.Count; for (Int16 i = 1; i < count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].Controls[1]; //get the value of attribute name. string id = CheckBox3.Attributes["name"]; } } happy coding..

        J Offline
        J Offline
        jainiraj
        wrote on last edited by
        #3

        thanks a lot...

        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