我在VB网络方面经验丰富,但仍然认为自己是ASP.net的新手,尽管我已经完成了很多项目。我在VB ASP网页中有一个绑定到AccessDataSource的gridview。该表显示了每个项目的信息,主要是每个阶段的日期。我想要做的是使表中的一列可点击,当点击它时,提示用户确认他们想要设置值,并在“确定”按下时,设置该单元格的值到数据库中的Now()值并刷新gridview。
我让gridview运行良好,设法使单元格可点击,并要求用户确认。但是在这里我被卡住,无论用户是单击确定还是取消,我都无法处理响应,我不知道如何最好地处理单元格值的更新。理想情况下,我希望尽可能保持代码为VB。对于下一步的任何建议都将不胜感激。
的GridView:
<asp:GridView ID="ItemGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ItemDataSource" EmptyDataText="There are no data records to display." AllowSorting="True" CellPadding="2" OnRowCommand="ItemGridView_RowCommand">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Item #" SortExpression="ID" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="Project" HeaderText="Project" SortExpression="Project" />
<asp:BoundField DataField="Item_Size" HeaderText="Size" SortExpression="Item_Size" />
<asp:TemplateField HeaderText="Finalized" SortExpression="Date_Item_Finalized">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Date_Item_Finalized") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="DateFinalizedRowLabel" runat="server" Text='<%# Bind("Date_Item_Finalized", "{0:dd/MM/yyyy}") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Date_Item_Sent" HeaderText="Sent" SortExpression="Date_Item_Sent" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Date_Item_at_Location1" HeaderText="At Location1" SortExpression="Date_Item_at_Location1" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Date_Left_Location1" HeaderText="Left Location1" SortExpression="Date_Left_Location1" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Date_Item_At_Site_Yard" HeaderText="At Location2" SortExpression="Date_Item_At_Site_Yard" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Date_Item_Left_Site_Yard" HeaderText="Left Location2" SortExpression="Date_Item_Left_Site_Yard" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Date_Item_On_Site" HeaderText="On Site" SortExpression="Date_Item_On_Site" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="Days Overdue" SortExpression="Days_Overdue">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Days_Overdue") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="DaysOverdueRowLabel" runat="server" Text='<%# Get_Days_Overdue(Eval("Date_Item_Finalized"), Eval("Date_Item_At_Site_Yard"), Eval("Date_Left_Location1"))%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
添加可点击属性:
Protected Sub ItemGridView_Databind_Tasks(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles ItemGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'This section adds a attributes to each cell in the "On Site" column
e.Row.Cells(9).Attributes.Add("onClick", "return confirm('Mark Item " & e.Row.Cells(0).Text & " as Onsite. Are You Sure?');")
e.Row.Cells(9).Attributes.Add("CommandName", "MarkOnSite")
e.Row.Cells(9).Attributes.Add("onmouseover", "this.style.cursor='pointer'")
e.Row.Cells(9).ToolTip = "Click to mark item as 'On Site'"
End If
End Sub