Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DataGrid Template column question

Posted on 2005-05-09
16
Medium Priority
?
204 Views
Last Modified: 2010-04-07
hi

this looks like simple..but i cant figure out a way to do it...propably some one can here can help me with that.

here is what i want to be able to do

basically i need to hide a column in datagrid..but i dont know which column but i know the control that column has...

//the below code is not right but i need to do something like that
 DataGrid1.Columns[e.Item.FindControl("btnEdit")].Visible=false;

and i dont want to enter column index bcz...i have columns generated automatically and i have teh template columns to the right (i dont want to move to left)....so the column # chages depending on the # of columns dataset has ...

so let me knwo...
thanks

0
Comment
Question by:praneetha
  • 9
  • 5
  • 2
16 Comments
 
LVL 13

Expert Comment

by:Torrwin
ID: 13961885
I know your index is changing, but does your column have a unique name?  Like: datagrid1.columns("CustomerID").visible = false
0
 
LVL 15

Author Comment

by:praneetha
ID: 13961887
well that line i wrote is in itemdatabound..but it does have to be in datagrid i guess...like i can hide them dependng on the proveleges of user...like right after binding the data to the datagrid.

Thanks
0
 
LVL 15

Author Comment

by:praneetha
ID: 13961897
that is what my column look slike..where would i give it name

<asp:TemplateColumn >
                  <ItemTemplate>
                        <asp:LinkButton Runat="server" CommandName="Edit" ID="btnedit" Runat="server">Edit</asp:LinkButton>
                  </ItemTemplate>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Accepted Solution

by:
Ramuncikas earned 2000 total points
ID: 13962046
Hey, praneetha

Try using this logic:
If your datagrid autogenerates colums and your template column to be hidden is to the right oh them, then you have to hide the last (column to the most right) of your datagrid.

Here is a solution how to hide the column most to the right even if it is a template column:

'this will hide first column from the right
CType(dg.Columns(dgColumns.Count - 1), TemplateColumn).Visible=False

'this will hide second column from the right
CType(dg.Columns(dgColumns.Count - 2), TemplateColumn).Visible=False

'and so on

This code will prevent datagrid from rendering the most right(second form the right) column of the datagrid. All you need to do is just put this statement in your code, sorround it with IF contition determining waether you need to hide the column or not.

Hope this will help
Ramuncikas
0
 
LVL 15

Author Comment

by:praneetha
ID: 13962078
hmm looks like a good idea...thanks..

so there is no way to find out which column the control is in..like i know there is "btnedit" and want to know which column it is in...

hey but thats the good idea...any more ideas...

thank you
0
 
LVL 15

Author Comment

by:praneetha
ID: 13962112
hey torrwin..how do i find the column name or give it a name...
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 13962133
Praneetha,

I don't know if your code is very special, but practically template columns appear ONLY to the right of autogenerated columns.

If you'd explain why it is so important to know WHAT colunm contains the button, I'd try to help.

Ramuncikas
0
 
LVL 13

Expert Comment

by:Torrwin
ID: 13962277
Well, I have been working mainly with VB.NET, and not ASP.NET lately, so I assumed it was part of the column.  

However, I have been looking at one of my old projects, and the only thing I could see is trying to set the header text and then try that.

<asp:TemplateColumn HeaderText="myColumn">
               <ItemTemplate>
                    <asp:LinkButton Runat="server" CommandName="Edit" ID="btnedit" Runat="server">Edit</asp:LinkButton>
               </ItemTemplate>


datagrid1.columns("myColumn").visible = false
0
 
LVL 15

Author Comment

by:praneetha
ID: 13962301
but

DataGrid1.Columns[int index].Visible=false or true...

loks like columns will only take index...not the name..it throws a compile time error
0
 
LVL 15

Author Comment

by:praneetha
ID: 13962302
but

DataGrid1.Columns[int index].Visible=false or true...

loks like columns will only take index...not the name..it throws a compile time error
0
 
LVL 15

Author Comment

by:praneetha
ID: 13962330
and for template columns being right.....

:) yep u r right..they always on right...

i actually do not have all autogenerae columns..i have all of them as template columns an di just wanted to explain why i dont want to use column index..i mean i just thought it would ne nicer way to refer it by edit column or something..instead of changing the code when i add more columns later..and i wa sjust not thinking when i said i dont want it on left..:) andmy code is not speical though..well prpably we can do it it that way too..but nope not my code right now...
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 13962435
Referencing a column by a control found in it just complicates the code and longens the run-time.

On the other hand you could just have some constants or an enum for columns you are going to reference

Ramuncikas
0
 
LVL 15

Author Comment

by:praneetha
ID: 13962449
yep i guess i am convinced with the soln u have given...will leave it open for few more hours before i accept your soln.

Thank You
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 13974801
So, Praneetha,

How is it going with template columns? :)

Ramuncikas
0
 
LVL 15

Author Comment

by:praneetha
ID: 13978263
sorry totally forgot about it.

Thanks...and thanks torrwin too
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 13984030
Pleased to hear that I could help :)

Good luck
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question