jeandoiron
asked on
Change AutoPostBack setting on a datagrid column from server-side VB.NET code.
I have a datagrid with columns that are bound to a datasource from SQL server table. The HTML code is the following;
<asp:datagrid id="dgAddressCorrection" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 180px" AllowPaging="True" OnPageIndexChanged="dgAddr essCorrect ion_Change " runat="server" CssClass="WebControl_DataG ridDef" PageSize="100" Width="1468px" AutoGenerateColumns="False " AllowSorting="True">
<Columns>
<asp:BoundColumn Visible="False" DataField="SourceID"></asp :BoundColu mn>
<asp:BoundColumn DataField="Name" SortExpression="Name" HeaderText="Name"></asp:Bo undColumn>
<asp:BoundColumn DataField="Address" SortExpression="Address" HeaderText="Address"></asp :BoundColu mn>
<asp:BoundColumn DataField="Phone" SortExpression="Phone" HeaderText="Main Phone"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="btnEdit" Text="Edit" Runat="server" Width="50px" CommandName="EditAddressCo rrection" CssClass="WebControl_Butto nDef"></as p:Button>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Overridden" HeaderStyle-HorizontalAlig n="Center" ItemStyle-HorizontalAlign= "Center">
<ItemTemplate>
<asp:CheckBox id="IsAddressOverriddenFie ld" AutoPostBack="True" OnCheckedChanged="EnableSa vebtn" Checked='<%# DataBinder.Eval(Container. DataItem," IsAddressO verridden" ) %>' runat="server" CssClass="WebControl_Check Box">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
On the server-side, I turn the AutoPostBack to false on the CheckBox column (ID=IsAddressOverriddenFie ld) with the following code;
Sub EnableSavebtn(ByVal sender As Object, ByVal e As EventArgs)
btnSaveOvr.Enabled = True
Dim i As Integer
For i = 0 To (dgAddressCorrection.Items .Count - 1)
Dim myCheckBox2 As CheckBox = CType(dgAddressCorrection. Items(i).C ells(5).Co ntrols(1), CheckBox)
myCheckBox2.AutoPostBack = False
Next
End Sub
This works, but I have to turn the AutoPostBack to false for every row in the datagrid. Is there a way to change the AutoPostBack for the whole column instead of doint it for every row? I only need to have AutoPostBack set to true for the first time the user click in one of the CheckBox in the datagrid, after that first click, I do not need AutoPostBack set to true.
<asp:datagrid id="dgAddressCorrection" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 180px" AllowPaging="True" OnPageIndexChanged="dgAddr
<Columns>
<asp:BoundColumn Visible="False" DataField="SourceID"></asp
<asp:BoundColumn DataField="Name" SortExpression="Name" HeaderText="Name"></asp:Bo
<asp:BoundColumn DataField="Address" SortExpression="Address" HeaderText="Address"></asp
<asp:BoundColumn DataField="Phone" SortExpression="Phone" HeaderText="Main Phone"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="btnEdit" Text="Edit" Runat="server" Width="50px" CommandName="EditAddressCo
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Overridden" HeaderStyle-HorizontalAlig
<ItemTemplate>
<asp:CheckBox id="IsAddressOverriddenFie
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
On the server-side, I turn the AutoPostBack to false on the CheckBox column (ID=IsAddressOverriddenFie
Sub EnableSavebtn(ByVal sender As Object, ByVal e As EventArgs)
btnSaveOvr.Enabled = True
Dim i As Integer
For i = 0 To (dgAddressCorrection.Items
Dim myCheckBox2 As CheckBox = CType(dgAddressCorrection.
myCheckBox2.AutoPostBack = False
Next
End Sub
This works, but I have to turn the AutoPostBack to false for every row in the datagrid. Is there a way to change the AutoPostBack for the whole column instead of doint it for every row? I only need to have AutoPostBack set to true for the first time the user click in one of the CheckBox in the datagrid, after that first click, I do not need AutoPostBack set to true.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
However, that disables the AutoPostBack for the each check box when the user clicks on it.