Creating Checkbox Dynamically in Data Grid using VB.NET Web Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • livmacca
    New Member
    • Mar 2008
    • 4

    Creating Checkbox Dynamically in Data Grid using VB.NET Web Form

    Hi,

    I am trying to create a web page whereby I first read data from Oracle Database and display the records out on the data grid. The data displayed is in order of one attribute say 'A' meaning that some records have the same value for 'A'. I need to display only 1 checkbox per group of records which has the same attribute 'A'. When the checkbox is checked, I need to update the database for all of the records with the same attribute 'A'.

    Does anyone knows how this can be done? I have managed to display the checkbox for beside all the records using the following code in the .aspx file but is clueless on how to make it such that i will have 1 checkbox per group of records.


    <TD><asp:datagr id id="DataGrid1" runat="server" ForeColor="Blac k" Font-Size="XX-Small" Font-Names="Verdana"
    AutoGenerateCol umns="False" Width="100%" Height="100%" HorizontalAlign ="Left" AllowSorting="T rue"
    BackColor="#C0C 0FF">
    <AlternatingIte mStyle HorizontalAlign ="Left" BorderStyle="So lid" Width="100%" VerticalAlign=" Middle" BackColor="#FFE 0C0"></AlternatingItem Style>
    <ItemStyle Font-Size="XX-Small" Font-Names="Verdana" HorizontalAlign ="Left" ForeColor="Blac k"
    Width="100%" VerticalAlign=" Middle" BackColor="#C0C 0FF"></ItemStyle>
    <HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" HorizontalAlign ="Center"
    ForeColor="Whit e" Width="100%" VerticalAlign=" Middle" BackColor="Dark SlateBlue"></HeaderStyle>
    <Columns>
    <asp:TemplateCo lumn HeaderText="Pro ductName">
    <ItemTemplate >
    <asp:CheckBox id="CheckBox1" runat="server" AutoPostBack="T rue"></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateCol umn>
    <asp:BoundColum n DataField="EVEN T_ID" HeaderText="Eve nt ID"></asp:BoundColumn >
    <asp:BoundColum n DataField="DEPO _ID" HeaderText="Dep ository ID"></asp:BoundColumn >
    <asp:BoundColum n DataField="SEC_ ID" HeaderText="GEM S Security ID"></asp:BoundColumn >
    <asp:BoundColum n DataField="SEC_ SHORT_DESC" HeaderText="Sec urity Description"></asp:BoundColumn >
    <asp:BoundColum n DataField="LIST _CNTRY" HeaderText="Cou ntry"></asp:BoundColumn >
    <asp:BoundColum n DataField="EX_D ATE" HeaderText="Ex-Date"></asp:BoundColumn >
    <asp:BoundColum n DataField="EFFE CTIVE_DATE" HeaderText="Eff ective Date"></asp:BoundColumn >
    <asp:BoundColum n DataField="CA_T YPE" HeaderText="CA Type"></asp:BoundColumn >
    <asp:BoundColum n DataField="M_V_ INDICATOR" HeaderText="Ind icator"></asp:BoundColumn >
    <asp:BoundColum n DataField="STAT US" HeaderText="Sta tus"></asp:BoundColumn >
    <asp:BoundColum n DataField="CREA TED_BY" HeaderText="Cre ated By"></asp:BoundColumn >
    <asp:BoundColum n DataField="CREA TED_DT_TM" HeaderText="Cre ated Date Time"></asp:BoundColumn >
    <asp:BoundColum n DataField="LAST _MOD_BY" HeaderText="Las t Modified By"></asp:BoundColumn >
    <asp:BoundColum n DataField="LAST _MOD_DT_TM" HeaderText="Las t Modified Date Time"></asp:BoundColumn >
    <asp:BoundColum n DataField="CA_F ILE_STATUS" HeaderText="CA File Status"></asp:BoundColumn >
    <asp:BoundColum n DataField="REMA RKS" HeaderText="Rem arks"></asp:BoundColumn >
    </Columns>
    </asp:datagrid></TD>


    Thanks!
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    I think you may be going about this slightly incorrectly. You've gone through the process of grabbing the database and using it as a data source for your grid, which is standard practice and for usual everyday tasks, this would be correct.

    However, in this case, what I think you'll need to do is parse the dataset that you grabbed from the database and iterate through it row by row and build your grid. When the current record holds a new attribute, add a row that contains your checkbox above the one you're currently working on, add a hidden field that contains a list of the keys that will be dynamically built from id's for the current group. As you parse a new record, you check to see if the group is still the same one, if it is, add it to the contents of the hidden field. If it's not the same, create a new row with a new checkbox and a new hidden field to repeat the process over.

    There might be a bit more of a slick way to do this, but I think this is the bare bones of the technique that will get you started.

    Comment

    • livmacca
      New Member
      • Mar 2008
      • 4

      #3
      Hi,

      Thanks very much for your suggestion! Think this is what I need !!.. but I am still not sure how to parse the dataset and iterate to compare the values. I was searching for some suggestion online but could not find any. Do you know how to iterate the data set through each row of results and comparing the first cell of each row with the other rows to see if they are the same? Lastly, how to I add a check box or other template columns to each row of datagrid as I am building it?




      Originally posted by balabaster
      I think you may be going about this slightly incorrectly. You've gone through the process of grabbing the database and using it as a data source for your grid, which is standard practice and for usual everyday tasks, this would be correct.

      However, in this case, what I think you'll need to do is parse the dataset that you grabbed from the database and iterate through it row by row and build your grid. When the current record holds a new attribute, add a row that contains your checkbox above the one you're currently working on, add a hidden field that contains a list of the keys that will be dynamically built from id's for the current group. As you parse a new record, you check to see if the group is still the same one, if it is, add it to the contents of the hidden field. If it's not the same, create a new row with a new checkbox and a new hidden field to repeat the process over.

      There might be a bit more of a slick way to do this, but I think this is the bare bones of the technique that will get you started.

      Comment

      Working...