vb code
Private Sub dgDefects_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDefects.ItemCommand
Dim iValue As Integer
iValue = Integer.Parse(CType(e.Item.Controls(5), TableCell).Text)
'handle defects on dgDefects Grid
If e.CommandName = "Increase" Then
CType(e.Item.Controls(5), TableCell).Text = (iValue + 1).ToString()
ElseIf e.CommandName = "Decrease" Then
If Not CType(e.Item.Controls(5), TableCell).Text <= "0" Then
CType(e.Item.Controls(5), TableCell).Text = (iValue - 1).ToString()
End If
End If
If CType(e.CommandSource, Button).Text = "Show Details" Then
dgDefects.Columns(7).Visible = True
Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
Dim c As Control
For Each c In dgi.Cells(7).Controls
c.Visible = True
Next
CType(e.CommandSource, Button).Text = "Hide Details"
ElseIf CType(e.CommandSource, Button).Text = "Hide Details" Then
dgDefects.Columns(7).Visible = False
Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
Dim c As Control
For Each c In dgi.Cells(7).Controls
c.Visible = False
Next
CType(e.CommandSource, Button).Text = "Show Details"
End If
End Sub 'dgDefects_ItemCommand
Private Sub dgDefects_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgDefects.ItemDataBound
Dim dgi As DataGridItem = e.Item
If dgi.ItemType = ListItemType.Item Or dgi.ItemType = ListItemType.AlternatingItem Then
Dim c As Control
For Each c In dgi.Cells(7).Controls
If TypeOf (c) Is System.Web.UI.WebControls.DataGrid Then
Dim id As Int32 = Int32.Parse(dgi.Cells(0).Text)
Dim dg As DataGrid = CType(c, DataGrid)
Dim dr As DataRow()
dr = m_dsDefects.Tables("Defect_Details").Select("Defect_ID=" & id)
If dr.Length > 0 Then
dg.DataSource = dr
dg.DataBind()
Else
Dim dt As DataTable = New DataTable
Dim dr2 As DataRow
Dim dtCol As DataColumn = New DataColumn
With dtCol
.ColumnName = "Detail Disposition"
.DataType = System.Type.GetType("System.String")
.DefaultValue = "NO DETAILS"
End With
dt.Columns.Add(dtCol)
' Add one row. Since it has default values, no need to set values.
dr2 = dt.NewRow
dt.Rows.Add(dr2)
dg.DataSource = dt
dg.DataBind()
End If
End If
Next
End If
End Sub
html
<form id="Form1" method="post" runat="server"><asp:label id="lblError" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 528px" runat="server"
Visible="False" Width="256px" Height="64px">Label</asp:label><asp:Button id="btnSaveAuditInfo" style="Z-INDEX: 125; LEFT: 632px; POSITION: absolute; TOP: 488px"
runat="server" Width="98px" Text="Complete Audit"></asp:Button><asp:Label id="lblAuditorId" style="Z-INDEX: 124; LEFT: 776px; POSITION: absolute; TOP: 24px"
runat="server" Visible="False" Enabled="False"></asp:Label><asp:textbox id="txtLotNum" style="Z-INDEX: 123; LEFT: 776px; POSITION: absolute; TOP: 136px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:textbox id="txtAuditType" style="Z-INDEX: 122; LEFT: 776px; POSITION: absolute; TOP: 80px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:textbox id="txtAuditor" style="Z-INDEX: 121; LEFT: 776px; POSITION: absolute; TOP: 192px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:label id="lblLotNumber" style="Z-INDEX: 120; LEFT: 776px; POSITION: absolute; TOP: 112px"
runat="server" Height="24px" Width="80px" ForeColor="White">Lot Number</asp:label><asp:label id="lblSampleSize" style="Z-INDEX: 119; LEFT: 776px; POSITION: absolute; TOP: 368px"
runat="server" Height="16px" Width="96px" ForeColor="White">Sample Size</asp:label><asp:textbox id="txtSampleSize" style="Z-INDEX: 116; LEFT: 776px; POSITION: absolute; TOP: 392px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:label id="lblMisPackAql" style="Z-INDEX: 118; LEFT: 776px; POSITION: absolute; TOP: 464px"
runat="server" Height="16px" Width="96px" ForeColor="White">MisPack AQL</asp:label><asp:textbox id="txtMisPackAQL" style="Z-INDEX: 117; LEFT: 776px; POSITION: absolute; TOP: 488px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:textbox id="txtCosAql" style="Z-INDEX: 115; LEFT: 776px; POSITION: absolute; TOP: 440px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:label id="lblAuditSize" style="Z-INDEX: 114; LEFT: 776px; POSITION: absolute; TOP: 56px"
runat="server" Height="16px" Width="72px" ForeColor="White">Audit Type</asp:label><asp:label id="lblMfg" style="Z-INDEX: 113; LEFT: 776px; POSITION: absolute; TOP: 320px" runat="server"
Height="16px" Width="40px" ForeColor="White">Supplier</asp:label><asp:textbox id="txtMfg" style="Z-INDEX: 110; LEFT: 776px; POSITION: absolute; TOP: 344px" runat="server"
Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:label id="lblPrdType" style="Z-INDEX: 112; LEFT: 776px; POSITION: absolute; TOP: 272px"
runat="server" Height="16px" Width="96px" ForeColor="White">Product Type</asp:label><asp:textbox id="txtPrdType" style="Z-INDEX: 109; LEFT: 776px; POSITION: absolute; TOP: 296px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:label id="lblLotSize" style="Z-INDEX: 111; LEFT: 776px; POSITION: absolute; TOP: 224px"
runat="server" Height="16px" Width="64px" ForeColor="White">Lot Size</asp:label><asp:textbox id="txtLotSize" style="Z-INDEX: 108; LEFT: 776px; POSITION: absolute; TOP: 248px"
runat="server" Width="184px" ForeColor="Black" BackColor="#E0E0E0"></asp:textbox><asp:label id="lblCosmeticAql" style="Z-INDEX: 107; LEFT: 776px; POSITION: absolute; TOP: 416px"
runat="server" Height="16px" Width="96px" ForeColor="White">Cosmetic AQL</asp:label><asp:label id="lblAuditors" style="Z-INDEX: 106; LEFT: 776px; POSITION: absolute; TOP: 168px"
runat="server" Height="24px" Width="56px" ForeColor="White">Auditor</asp:label><asp:label id="lblCosDefects" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 80px"
runat="server" Width="152px" Height="16px" Font-Size="Larger" ForeColor="White">Cosmetic Defects</asp:label><asp:label id="lblAudit" style="Z-INDEX: 103; LEFT: 392px; POSITION: absolute; TOP: 80px" runat="server"
Width="152px" Height="16px" Font-Size="Larger" ForeColor="White">TOI Auditors Center</asp:label><asp:image id="Image1" style="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 8px" runat="server"
Width="264px" Height="72px" ImageUrl="file:///C:\Inetpub\wwwroot\TOIAUDIT\Images\transitions-logo.gif"></asp:image>
<DIV style="OVERFLOW-Y: scroll; Z-INDEX: 105; LEFT: 16px; WIDTH: 525px; POSITION: absolute; TOP: 104px; HEIGHT: 360px"><asp:datagrid id="dgDefects" runat="server" Width="400px" Height="200px" CellPadding="3" BackColor="White"
BorderWidth="2px" BorderStyle="Ridge" BorderColor="White" AutoGenerateColumns="False" CellSpacing="1" GridLines="None"><SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle><ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle><HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" BackColor="#4A3C8C"></HeaderStyle><FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle><Columns><asp:BoundColumn Visible="False" DataField="Defect_ID" HeaderText="ID"></asp:BoundColumn><asp:ButtonColumn Text="Increase" ButtonType="PushButton" HeaderText="Add One" CommandName="Increase"></asp:ButtonColumn><asp:ButtonColumn Text="Decrease" ButtonType="PushButton" HeaderText="Subtract One" CommandName="Decrease"></asp:ButtonColumn><asp:BoundColumn DataField="Defect" HeaderText="Defect Description"></asp:BoundColumn><asp:BoundColumn DataField="Defect_Acronym" HeaderText="Defect Acronym"></asp:BoundColumn><asp:BoundColumn DataField="Defect_NumDefects" HeaderText="Number Found"></asp:BoundColumn><asp:ButtonColumn Text="Show Details" ButtonType="PushButton" HeaderText="Details">
Thank you for posting in the community!
I will continue assist you on your further issue in this post :-)
================================================
I have reviewd your post, there are some points I do not fully understand.
Please clarify them for me.
In your "what I need to do is draw out a check list box", what does your
"check list box" mean?
Based on your description, I see you want to use checkbox control to trap
the selection state of the row. I think you may add a template column to
your Master datagrid. Like this:
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="trapselection" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
Then, in the "submit" button's click event, you can iterate through the
grid, and collect the selection information, like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dgi As DataGridItem
For Each dgi In Master.Items
Dim tc As TableCell = dgi.Cells(0)
Dim c As Control
For Each c In tc.Controls
If TypeOf (c) Is System.Web.UI.WebControls.CheckBox Then
Dim cb As CheckBox = CType(c, CheckBox)
If cb.Checked = True Then
Me.Response.Write("The " & dgi.ItemIndex.ToString()
& "th row is selected<br>")
End If
End If
Next
Next
End Sub
For your second question, I am not fully understand what "With the latter
column all set to false" means, is this the issue?
Also, in the html code you pasted, I can not see the 7th column, which is
the "details" datagrid, without this column's html code, I can not figure
out the cause.
Hope my reply makes sense to you.
I will wait for your further feedback.
=============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
I'm sorry I posted the wrong HTML code. Here is the correct code...
HeaderText="Details"></asp:ButtonColumn>
<asp:TemplateColumn visible="false" HeaderText="Defect Details">
<itemtemplate>
<asp:DataGrid Runat="server" ID="Details"
visible="false"></asp:DataGrid>
</itemtemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#C6C3C6"></PagerStyle>
</asp:datagrid></DIV>
Now as for the other problem with the details datagrid. I used the
example that you gave me for displaying master/details. In your example
you encapsulate a datagrid within a datagrid and bind the encapsulated
datagrid to the details records. When I click the button the details
part of the grid is drawn but instead of one column of records I get
two. The first column is titled Row Errors and the second column is
titled Has Errors. The amount of rows that display in the details grid
match the amount of details that need to be displayed yet the details
are not displayed. The first column is blank the second column has the
word false displayed for all the rows. I hope this helps clarify the
issue.
I also asked about the checklist as I want to display the details in a
checklist box so that I can trap the details the users select. I will
try to implement the code sample that you provided and I will report my
results. Once again your help has proved to be invaluable to me.
Thanks in advance,
PatLaf
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks very much for your feedback.
======================================================
From your further html code, I see you use your "details" datagrid in
TemplateColumn(Just as I do).
Also, from your first paragraph's description, I understand your issue:
When you click the "Show Details" button, your "details" datagrid displays,
but it does not show well.
Based on your statement " but instead of one column of records I get two.",
I think your "details" datagrid should only display 1 column. But it shows
2 columns:
The first column with title "Row Errors" and empty cell content, while the
second's title "Has Errors" with the cell content "false".
In your code behind, I can not find anything incorrect, and the code
provides me nothing about the datasouce of the "details" datagrid. Anyway,
I think the key point is the "dgDefects_ItemDataBound" method, you should
check if your "details" datagrid is bound well. You may set a breakpoint at:
dr = m_dsDefects.Tables("Defect_Details").Select("Defect_ID=" & id)
to determine if the DataRow array "dr" contains what you wanted to show.
Because your dgDefects_ItemCommand method only enable the visibility of
your datagrid, if your "details" datagrid is bound correctly, your datagrid
should show well.
From your second paragraph, I found that you want to add the checkbox
column to the "details" datagrid not the "Master" datagrid. My sample code
in last project shows you how to add the datagrid column to your "Master"
datagrid, I think you should do the same to you "details" datagrid(The html
code is the same)
======================================================
Please apply my suggestion to see if it resolved your problem.
If you still have anything unclear, please feel free to tell me, I will
help you.
I have another question.....of course.......you stated that you attached
the entire project in your post.
Thanks very much for your feedback.
You are welcome, I am glad to work with you :-)
I really has attached the entire project in that post, I just use Outlook
Express to view that post, and find that attachment project.
I think you may use IE to visit the newsgroup. It seems that the IE will
not display the attachment, I suggest you use Outlook Express to view that
post.(I also think OE is more convinience to view newsgroup than IE).
If you still can not use OE to see the attachment, please tell me your TRUE
e-mail address(I am not sure if "plafe...@transitions.com" at your title
is your valid email address), I will sent to you that project.(Anyway, I
will try to use "plafe...@transitions.com" to send the project to you)
Ok, I hope you have a good luck. If you have any further concern, please
feel free to post, I will help you on it.
Have a nice day!!
Have you received my project?
If you still have anything unclear, please feel free to tell me, I will
help you.
Best regards,
Dim iValue As Integer
iValue = Integer.Parse(CType(e.Item.Controls(5), TableCell).Text)
'handle defects on dgDefects Grid
If e.CommandName = "Increase" Then
CType(e.Item.Controls(5), TableCell).Text = (iValue + 1).ToString()
ElseIf e.CommandName = "Decrease" Then
If Not CType(e.Item.Controls(5), TableCell).Text <= "0" Then
CType(e.Item.Controls(5), TableCell).Text = (iValue - 1).ToString()
End If
End If
Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
If CType(e.CommandSource, Button).Text = "Show Details" Then
dgDefects.Columns(7).Visible = True
Dim c As Control
For Each c In dgi.Cells(7).Controls
c.Visible = True
Next
Me.VisibleDataGrid = Me.VisibleDataGrid + 1
CType(e.CommandSource, Button).Text = "Hide Details"
ElseIf CType(e.CommandSource, Button).Text = "Hide Details" Then
If Me.VisibleDataGrid <= 1 Then
dgDefects.Columns(7).Visible = False
End If
Dim c As Control
For Each c In dgi.Cells(7).Controls
c.Visible = False
Next
Me.VisibleDataGrid = Me.VisibleDataGrid - 1
CType(e.CommandSource, Button).Text = "Show Details"
End If
'collect any selected checkbox items from the details grid
For Each dgi In dgDefects.Items
Dim tc As TableCell = dgi.Cells(7)
Dim c As Control
For Each c In tc.Controls
Dim Discon As Boolean = CType(e.Item.FindControl("dgDetails"), CheckBox).Checked
If TypeOf (c) Is System.Web.UI.WebControls.CheckBox Then
Dim cb As CheckBox = CType(c, CheckBox)
If cb.Checked = True Then
Me.Response.Write("The " & dgi.ItemIndex.ToString() & "th row is selected<br>")
End If
End If
Next c
Next dgi
End Sub 'dgDefects_ItemCommand
I get the controls collection yet none of them are check boxes. What should I do? I am once again confused.
Thank again in advance,
I really appreciate the help.
Regards,
Patrick Laferriere
I have received your positive feedback, thanks very much :-)
For your 2 further concern, I will do some research on it, and I will reply
to you ASAP.
Also, as you said, the Typed DataSet does not work for you? Have you
received my project and tested it at your side? It only needs the default
database of SqlServer, and it works well on my side.
Thanks for your cooperation.
Sorry for letting you wait so long time.
I have reviewed your VB.net code, I think the problem code snippet should
be:
For Each dgi In dgDefects.Items
Dim tc As TableCell = dgi.Cells(7)
Dim c As Control
For Each c In tc.Controls
Dim Discon As Boolean = CType(e.Item.FindControl("dgDetails"),
CheckBox).Checked
If TypeOf (c) Is System.Web.UI.WebControls.CheckBox Then
Dim cb As CheckBox = CType(c, CheckBox)
If cb.Checked = True Then
Me.Response.Write("The " & dgi.ItemIndex.ToString() & "th
row is selected<br>")
End If
End If
Next c
Next dgi
In the code, I think "dgDetails" is the id of the details datagrid. But in
your code, you find this control and convert it into CheckBox, which is not
correct.
I think you should first find the details datagrid, then loop through all
the rows in the DETAILS datagrid and find the CheckBox. Like this(Note: I
did not compile this code at my side, so there may be some small error in
the code):
For Each dgi In dgDefects.Items
Dim tc As TableCell = dgi.Cells(7)
Dim c As Control
For Each c In tc.Controls
If TypeOf (c) Is System.Web.UI.WebControls.DataGrid Then
Dim dgdetails As DataGrid =
CType(e.Item.FindControl("dgDetails"), DataGrid)
Dim dgi as DataGridItem
For Each dgi in dgdetails Then
If(CType(dgi.FindControl("checkboxid"),
CheckBox).Checked = True)
Me.Response.Write("The " &
dgi.ItemIndex.ToString() & "th row is selected in Details DataGrid<br>")
End If
Next di
End If
Next c
Next dgi
Also, in your program logic in your code snippet, you hook into the MASTER
datagrid's ItemCommand event, then want to loop through the DETAILS
datagrid's each row and collect any selected checkbox items. I think this
is a strange logic, because the DETAILS datagrid may still be invisible,
but you continue loop through the invisible DETAILS datagrid.
Have you received my sample code project ?
In that project, I use an individual button, in which click event, I show
all the checked items in VISIBLE details datagrid.
================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Here's what I tried last....
Private Sub dgDetails_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgdetails.ItemCommand
Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
'collect any selected checkbox items from the details grid
For Each dgi In dgDefects.Items
Dim tc As TableCell = dgi.Cells(7)
Dim c As Control
Dim dgi2 As DataGridItem
For Each c In tc.Controls
If TypeOf (c) Is System.Web.UI.WebControls.DataGrid Then
Dim dgdetails As DataGrid = CType(e.Item.FindControl("dgDetails"), DataGrid)
For Each dgi2 In dgdetails.Items
If CType(dgi2.FindControl("chkboxSelDetails"), CheckBox).Checked = True Then
Me.Response.Write("The " & dgi2.ItemIndex.ToString() & "th row is selected in Details datagrid<br>")
End If
Next dgi2
End If
Next c
Next dgi
End Sub 'dgDetails_ItemCommand
If I could just get the event to fire I think I might actually get closer to finishing this project....
Thanks again for your help,
Pat
I have added a reply to another new post of you in this group. Please
follow up there, I will work with you there.
Thanks for your understanding.