Keep in mind that for this I am limited to using ASP .NET 1.1, as for this environment I cannot upgrade to 2.0 or beyond
Essentially, I have a very simple datagrid that has a checkbox in one of the columns, which is a template column...the code for the datagrid is this:
<asp:datagrid id="dgDates" OnItemCommand="gridEventHandler" BorderColor="Black" BorderWidth="1开发者_JAVA百科px"
CellPadding="3" runat="server" AutoGenerateColumns="False" HorizontalAlign="Left" AllowSorting="True"
OnSortCommand="SortData" OnItemDataBound="gridItemDataBound">
<HeaderStyle Font-Underline="True" Font-Bold="True" HorizontalAlign="Center" ForeColor="Black"
BackColor="#D4D0C8"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="strParameterName" SortExpression="strParameterName" HeaderText="Parameter Name"></asp:BoundColumn>
<asp:BoundColumn DataField="dtParameterValue" SortExpression="dtParameterValue" HeaderText="Parameter Value"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Status" SortExpression="blnStatic">
<ItemTemplate>
<asp:CheckBox ID="cbStaticRolling" OnCheckedChanged="staticRolling_CheckedChanged" Runat="server" AutoPostBack="true"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Now, I want to evaluate a stored proc based on whether a checkbox for a particular row is set to true or not, so I have this as an eventhandler for the datagrid:
Protected Sub gridItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If IsPostBack Then
Dim intRptSchedulingDatesID As Integer
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
cbStaticRolling = CType(e.Item.FindControl("cbStaticRolling"), CheckBox)
intRptSchedulingDatesID = CType(e.Item.DataItem, System.Data.DataRowView).Item("intRptSchedulingDatesID")
If cbStaticRolling.Checked Then
SqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings(Web.Global.CfgKeyConnStringADMIN), "dbo.spRptSchedulingDate_update", intRptSchedulingDatesID, True)
ElseIf Not cbStaticRolling.Checked Then
SqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings(Web.Global.CfgKeyConnStringADMIN), "dbo.spRptSchedulingDate_update", intRptSchedulingDatesID, False)
End If
End If
End If
End Sub
Now, my issue is that when I set cbStaticRolling to the CheckBox control through FindControl on the e argument, it seems to set the variable okay, but doesn't seem to be setting the right one, or setting it properly, because "Checked" property is false regardless of whether I check the box or not
You are not setting the value for the checkbox for when it is bound to the result set, in your template column you need something like this:
<ItemTemplate>
<asp:Label id="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FirstName") %>' >
</asp:Label>
</ItemTemplate>
Since you are setting a checkbox, you might have to use the value tag instead of the text, and return true or false from the stored proc.
精彩评论