Bind Data To Checkboxlist In Gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mercea
    New Member
    • Aug 2007
    • 35

    Bind Data To Checkboxlist In Gridview

    hi all,

    i have inserted a checkboxlist in my gridview using the <item template>. but i want the checkbox text to be genarated at runtime i.e via textboxes(user input). i have 5 textboxes and 5 checkboxes per row. so i want the text of textbox1= checkbox1's text. and for each row in the gridview, the checkbox's texts will be changed. any ideas?

    - is it possible to disable a link once it has been visited by a particular user?
  • Sakalicek
    New Member
    • Mar 2007
    • 51

    #2
    Originally posted by mercea
    hi all,

    i have inserted a checkboxlist in my gridview using the <item template>. but i want the checkbox text to be genarated at runtime i.e via textboxes(user input). i have 5 textboxes and 5 checkboxes per row. so i want the text of textbox1= checkbox1's text. and for each row in the gridview, the checkbox's texts will be changed. any ideas?

    - is it possible to disable a link once it has been visited by a particular user?
    So if I understand it well, you would like to set checkboxes texts depending on values in textboxes?

    Well you can use something like this:

    // HTML

    ....
    <asp:CheckBox ID="chBox" .... >
    <asp:TextBox ID="txtBox" ... >
    .....

    // end HTML

    DataGrid grid;
    CheckBox checkBox;
    TextBox textBox;

    foreach (GridViewRow grdViewRow in grid.Rows)
    {
    checkBox = (CheckBox) grdViewRow.Find Control("chBox" );
    textBox= (TextBox) grdViewRow.Find Control("txtBox ");

    checkBox.Text = textBox.Text;

    }

    or you may use also grid. FindControl();

    Let me know if this helped.
    Zdenek.

    Comment

    • Sakalicek
      New Member
      • Mar 2007
      • 51

      #3
      Originally posted by Sakalicek
      So if I understand it well, you would like to set checkboxes texts depending on values in textboxes?

      Well you can use something like this:

      // HTML

      ....
      <asp:CheckBox ID="chBox" .... >
      <asp:TextBox ID="txtBox" ... >
      .....

      // end HTML

      DataGrid grid;
      CheckBox checkBox;
      TextBox textBox;

      foreach (GridViewRow grdViewRow in grid.Rows)
      {
      checkBox = (CheckBox) grdViewRow.Find Control("chBox" );
      textBox= (TextBox) grdViewRow.Find Control("txtBox ");

      checkBox.Text = textBox.Text;

      }

      or you may use also grid. FindControl();

      Let me know if this helped.
      Zdenek.
      And maybe this wount help.
      Try to join this on some DataGrid method like OnItemCommand.
      Or to TextBox method OnTextChanged or something.
      There should be param DataGridCommand EventArgs e.
      Then you can use something similiar.

      Code:
      ImageButton linkButtonDelete = (ImageButton)e.Item.Cells[3].FindControl("deleteButton");
      
              LinkButton linkbuttonYes = (LinkButton)e.Item.Cells[4].FindControl("deleteYes");
      
              LinkButton linkbuttonNo = (LinkButton)e.Item.Cells[4].FindControl("deleteNo");
      
              ImageButton linkbuttonEdit = (ImageButton)e.Item.Cells[2].FindControl("editButton");
      
              LinkButton linkbuttonUpdate = (LinkButton)e.Item.Cells[2].FindControl("editUpdate");
      
              LinkButton linkbuttonCancel = (LinkButton)e.Item.Cells[2].FindControl("editCancel");
      
              TextBox textBoxMapValue = (TextBox)e.Item.Cells[2].FindControl("listMapValue");
      
              DropDownList cmbMapType = (DropDownList)e.Item.Cells[2].FindControl("cmbMapType");
      
              Label lblMapItemType = (Label)e.Item.Cells[1].FindControl("lblMapItemType");
      
              Label lblMapItemValue = (Label)e.Item.Cells[0].FindControl("lblMapItemValue");
      Remark: The code doesnt relay with your problem ,its just a sample how to work with it.

      Enjoy, Zdenek.

      Comment

      • Sakalicek
        New Member
        • Mar 2007
        • 51

        #4
        Was it helpfull or not?

        Comment

        Working...