GridView Control - Always show edit mode?

M

Mel

I have a grid view control with just to columns. The first column is
a checkbox (active/inactive user) and the second column is just text
(user full name). I want to be able to edit only the checkbox field.
Do I really need to have an edit button and an Update button? I would
rather have the user just check/uncheck the box and have the Access
Database in the background update. Is there any way to do that?

Any ideas would be greatly appreciated,
Mel
 
L

Larry Bud

I have a grid view control with just to columns. The first column is
a checkbox (active/inactive user) and the second column is just text
(user full name). I want to be able to edit only the checkbox field.
Do I really need to have an edit button and an Update button? I would
rather have the user just check/uncheck the box and have the Access
Database in the background update. Is there any way to do that?

Make it a template field and place a checkbox in the item template.
Then handle it when it's clicked.
 
M

Mel

Make it a template field and place a checkbox in the item template.
Then handle it when it's clicked.

Okay I made the checkbox a template field. When I click on the
checkbox it does not call the CheckChanged event. It doesn't do
anything. What am I doing wrong? Do you have an example you could
post?


'START OF EXAMPLE CODE
<asp:GridView ID="gvUsers" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False"
BackColor="Transparent" BorderColor="Transparent"
BorderStyle="None" CellPadding="2"
DataSourceID="adsUsers" EmptyDataText="No Users at
this time." Font-Names="Verdana"
Font-Size="Small" ForeColor="#333333"
Height="100%" HorizontalAlign="Left" PageSize="25"
Style="font-family: Verdana" TabIndex="13"
Width="53%">
<PagerSettings FirstPageImageUrl="~/Images/
first_button.bmp" FirstPageText="First"
LastPageImageUrl="~/Images/last_button.bmp"
LastPageText="Last" Mode="NumericFirstLast"
NextPageImageUrl="~/Images/next_button.bmp"
NextPageText="Next" PreviousPageImageUrl="~/Images/prev_button.bmp"
PreviousPageText="Prev" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<EmptyDataRowStyle HorizontalAlign="Left" />
<RowStyle BackColor="#E3EAEB"
HorizontalAlign="Left" Wrap="True" />
<EditRowStyle BackColor="Yellow" />
<SelectedRowStyle BackColor="#C5BBAF" Font-
Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="White" ForeColor="#1C5E55"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Active Status"
SortExpression="Active Status">
<ItemTemplate>
<asp:CheckBox ID="chkActiveStatus"
runat="server" Checked='<%# Bind("[Active Status]") %>'
OnCheckedChanged="chkActiveStatus_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rep Full Name"
SortExpression="Rep Full Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2"
runat="server" Text='<%# Bind("[Rep Full Name]") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# Bind("[Rep Full Name]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
'END OF EXAMPLE CODE
 
M

Mel

Make it a template field and place a checkbox in the item template.
Then handle it when it's clicked.

Okay I made the checkbox a template field. When I click on the
checkbox it does not call the CheckChanged event. It doesn't do
anything. What am I doing wrong? Do you have an example you could
post?

'START OF EXAMPLE CODE
<asp:GridView ID="gvUsers" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False"
BackColor="Transparent" BorderColor="Transparent"
BorderStyle="None" CellPadding="2"
DataSourceID="adsUsers" EmptyDataText="No Users at
this time." Font-Names="Verdana"
Font-Size="Small" ForeColor="#333333"
Height="100%" HorizontalAlign="Left" PageSize="25"
Style="font-family: Verdana" TabIndex="13"
Width="53%">
<PagerSettings FirstPageImageUrl="~/Images/
first_button.bmp" FirstPageText="First"
LastPageImageUrl="~/Images/last_button.bmp"
LastPageText="Last" Mode="NumericFirstLast"
NextPageImageUrl="~/Images/next_button.bmp"
NextPageText="Next" PreviousPageImageUrl="~/Images/prev_button.bmp"
PreviousPageText="Prev" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<EmptyDataRowStyle HorizontalAlign="Left" />
<RowStyle BackColor="#E3EAEB"
HorizontalAlign="Left" Wrap="True" />
<EditRowStyle BackColor="Yellow" />
<SelectedRowStyle BackColor="#C5BBAF" Font-
Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="White" ForeColor="#1C5E55"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Active Status"
SortExpression="Active Status">
<ItemTemplate>
<asp:CheckBox ID="chkActiveStatus"
runat="server" Checked='<%# Bind("[Active Status]") %>'
OnCheckedChanged="chkActiveStatus_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rep Full Name"
SortExpression="Rep Full Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2"
runat="server" Text='<%# Bind("[Rep Full Name]") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# Bind("[Rep Full Name]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
'END OF EXAMPLE CODE

Okay now I can capture the checkbox click event. I had to move my
DataBind code in the Page Load event. Thanks.

If Page.IsPostBack = False Then
adsUsers.SelectCommand = "SELECT [Active Status], [Rep
Full Name] FROM [Rep Data] WHERE [Principal Contact] = False AND [Rep
Company] = '" & strCompanyName & "' ORDER BY [Rep Full Name]"
adsUsers.DataBind()
gvUsers.DataBind()
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top