Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Mar 2008
Posts: 4
#1: Mar 29 '08
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:datagrid id="DataGrid1" runat="server" ForeColor="Black" Font-Size="XX-Small" Font-Names="Verdana"
AutoGenerateColumns="False" Width="100%" Height="100%" HorizontalAlign="Left" AllowSorting="True"
BackColor="#C0C0FF">
<AlternatingItemStyle HorizontalAlign="Left" BorderStyle="Solid" Width="100%" VerticalAlign="Middle" BackColor="#FFE0C0"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Verdana" HorizontalAlign="Left" ForeColor="Black"
Width="100%" VerticalAlign="Middle" BackColor="#C0C0FF"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" HorizontalAlign="Center"
ForeColor="White" Width="100%" VerticalAlign="Middle" BackColor="DarkSlateBlue"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="ProductName">
<ItemTemplate>
<asp:CheckBox id="CheckBox1" runat="server" AutoPostBack="True"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="EVENT_ID" HeaderText="Event ID"></asp:BoundColumn>
<asp:BoundColumn DataField="DEPO_ID" HeaderText="Depository ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SEC_ID" HeaderText="GEMS Security ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SEC_SHORT_DESC" HeaderText="Security Description"></asp:BoundColumn>
<asp:BoundColumn DataField="LIST_CNTRY" HeaderText="Country"></asp:BoundColumn>
<asp:BoundColumn DataField="EX_DATE" HeaderText="Ex-Date"></asp:BoundColumn>
<asp:BoundColumn DataField="EFFECTIVE_DATE" HeaderText="Effective Date"></asp:BoundColumn>
<asp:BoundColumn DataField="CA_TYPE" HeaderText="CA Type"></asp:BoundColumn>
<asp:BoundColumn DataField="M_V_INDICATOR" HeaderText="Indicator"></asp:BoundColumn>
<asp:BoundColumn DataField="STATUS" HeaderText="Status"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_BY" HeaderText="Created By"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_DT_TM" HeaderText="Created Date Time"></asp:BoundColumn>
<asp:BoundColumn DataField="LAST_MOD_BY" HeaderText="Last Modified By"></asp:BoundColumn>
<asp:BoundColumn DataField="LAST_MOD_DT_TM" HeaderText="Last Modified Date Time"></asp:BoundColumn>
<asp:BoundColumn DataField="CA_FILE_STATUS" HeaderText="CA File Status"></asp:BoundColumn>
<asp:BoundColumn DataField="REMARKS" HeaderText="Remarks"></asp:BoundColumn>
</Columns>
</asp:datagrid></TD>


Thanks!
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#2: Mar 30 '08

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


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.
Newbie
 
Join Date: Mar 2008
Posts: 4
#3: Apr 1 '08

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


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?




Quote:

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.

Reply