Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2003, 02:13 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default pl help me urgent datagrid

Hi

i have one datagrid and 4 checkboxes(asume chk1,chk2,chk3,chk4) in my web form.
when ever user checked the
chk3 then only i want to show edit option in datagrid.

i tried following 2 ways but both failed

 1. degign time i declared my datagrid as
    <asp:datagrid id="grd" AutoGenerateColumns="true" OnCancelCommand="doitemcancel" OnUpdateCommand="doitemupdate"
onEditCommand="doitemedit" PagerStyle-HorizontalAlign="Right" AllowPaging="true" PagerStyle-Mode="NumericPages"
PageSize="20" Runat="server">
<Columns>
    <asp:EditCommandColumn EditText="edit" CancelText="cancel" UpdateText="update" />
</Columns>
</asp:datagrid>

in this case i dont know how to hide this editcommandcolumn in runtime.

 2.this time i didn't declared columns in design time
        <asp:datagrid id="grd" AutoGenerateColumns="true" OnCancelCommand="doitemcancel" OnUpdateCommand="doitemupdate"
onEditCommand="doitemedit" PagerStyle-HorizontalAlign="Right" AllowPaging="true" PagerStyle-Mode="NumericPages"
PageSize="20" Runat="server">
</asp:datagrid>

  and runtime i created controle like

Protected x As New System.Web.UI.WebControls.EditCommandColumn

x.EditText = "edit"
grd.Columns(.add(x))

        but here problem is doitemedit(which declared in oneditcommand) method is not firing

pl help me how to do this.

thanks


 
Old September 12th, 2003, 09:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Setup your datagrid in the ASPX file like this (note my bolded addition):

    <asp:datagrid id="grd" AutoGenerateColumns="true" OnCancelCommand="doitemcancel" OnUpdateCommand="doitemupdate"
onEditCommand="doitemedit" PagerStyle-HorizontalAlign="Right" AllowPaging="true" PagerStyle-Mode="NumericPages"
PageSize="20" Runat="server">
<Columns>
    <asp:EditCommandColumn EditText="edit" CancelText="cancel" UpdateText="update" Visible="False"/>
</Columns>
</asp:datagrid>

Then in your codebehind (you could put it in page load if you wanted to, or in the event handler for the checkbox):

grd.Columns(x).Visible = chk3.Checked
(where x is the proper column index number of your EditCommandColumn column.)

Now every time the page loads (or when you un/check the chk3), the visibility of that datagrid column will be set based on the status of the checkbox. Note that you need to ensure that the checkbox causes a postback so the datagrid is redrawn. You *shouldn't* need to rebind the datagrid however because the column is already there, it's just not visible.

Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid problem urgent pl. Komila General .NET 1 March 31st, 2007 04:15 PM
How to get datagrid selected index pl help me msrnivas General .NET 1 July 1st, 2005 08:03 AM
datagrid problem urgent pls. dsmportal Pro VB.NET 2002/2003 0 February 7th, 2005 09:00 PM
Urgent: Other control in Datagrid mrleokarthik Pro VB 6 0 November 27th, 2003 01:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.