Sei sulla pagina 1di 29

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.

or
g/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
/>
<meta name="keywords" content="Datagrid,header,text, Datagrid header text" />
<meta name="description" content="Hi, I'm wondering how can i change the datagri
d header text at runtime so that it keeps the sorting enabled? I can do; e.Item.
Cells[0].Text = &quot;foo&quot;; But then foo is" />

<!-- CSS Stylesheet -->


<style type="text/css" id="vbulletin_css">
/*

vBulletin 3.8.6 CSS


Style: 'Velocity Reviews 3.8'; Style ID: 4
*/
@import url("http://www.velocityreviews.com/forums/clientscript/vbulletin_css/st
yle-c3e162f0-00004.css");
</style>
<link rel="stylesheet" type="text/css" href="http://www.velocityreviews.com/foru
ms/clientscript/vbulletin_important.css?v=386" />

<!-- / CSS Stylesheet -->


<script type="text/javascript" src="/forums/clientscript/yui/yahoo-dom-event/yah
oo-dom-event.js?v=386"></script>
<script type="text/javascript" src="/forums/clientscript/yui/connection/connecti
on-min.js?v=386"></script>
<script type="text/javascript">
<!--
var SESSIONURL = "s=11d32f72eaf54907bd730b922aff6ca4&";
var SECURITYTOKEN = "guest";
var IMGDIR_MISC = "/forums/images/misc";
var vb_disable_ajax = parseInt("0", 10);
// -->
</script>
<script type="text/javascript" src="/forums/clientscript/vbulletin_global.js?v=3
86"></script>
<script type="text/javascript" src="/forums/clientscript/vbulletin_menu.js?v=386
"></script>

<title> Datagrid header text</title>


<script type="text/javascript" src="clientscript/vbulletin_post_loader.j
s?v=386"></script>
<style type="text/css" id="vbulletin_showthread_css">
<!--
#links div { white-space: nowrap; }
#links img { vertical-align: middle; }
-->
</style>
</head>
<body onload="">
<div class="headerimg"><a href="http://www.velocityreviews.com"><img src="/forum
s/images/template/header.jpg" alt="Velocity Reviews - Computer Hardware Reviews"
width="500" height="100" /></a></div>
<!-- content table -->

<table cellpadding="0" cellspacing="0" border="0" align="center" class="


navigation" width="100%">
<tr align="center">
<td class="navleft"></td>
<td class="navitem"><a href="http://www.velocityreviews.
com">Home</a></td>
<td class="navitem"><a href="http://www.velocityreviews.
com/forums/">Forums</a></td>
<td class="navitem"><a href="/reviews/">Reviews</a></td>
<td class="navitem"><a href="/guides/">Guides</a></td>
<td class="navitem"><a href="http://www.velocityreviews.
com/forums/f16-newsgroups.html">Newsgroups</a></td>

<td class="navitem"><a href="http://www.velocityreviews.


com/forums/register.php" rel="nofollow">Register</a></td>

<td id="navbar_search" class="navitem"><a href="


http://www.velocityreviews.com/forums/search.php" accesskey="4" rel="nofollow">S
earch</a> <script type="text/javascript"> vbmenu_register("navbar_search"); </sc
ript></td>

<td width="100%" align="right">

<!-- login form -->


<form action="http://www.velocityreviews.com/forums/login.php?do
=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password,
vb_login_md5password_utf, 0)">
<script type="text/javascript" src="http://www.velocityreviews.c
om/forums/clientscript/vbulletin_md5.js?v=386"></script>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="white-space: nowrap;font-size:12px;font-weigh
t:bold;color:#fff;padding-right:3px;">Member Login:</td>
<td style="padding-right:3px;"><input type="text" class=
"bginput2" style="font-size: 11px" name="vb_login_username" id="navbar_username"
size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.valu
e == 'User Name') this.value = '';" /></td>
<td style="padding-right:3px;"><input type="password" cl
ass="bginput2" style="font-size: 11px" name="vb_login_password" id="navbar_passw
ord" size="10" tabindex="102" /></td>
<td class="smallfont" nowrap="nowrap" style="margin-right:3px;"><label for="cb_c
ookieuser_navbar"><input type="checkbox" name="cookieuser" value="1" tabindex="1
03" id="cb_cookieuser_navbar" accesskey="c" /></label></td>
<td><input type="submit" class="lbutton" value="" tabind
ex="104" title="Enter your username and password in the boxes provided to login,
or click the 'register' button to create a profile for yourself." accesskey="s"
/></td>
</tr>
</table>
<input type="hidden" name="s" value="11d32f72eaf54907bd730b922af
f6ca4" />
<input type="hidden" name="securitytoken" value="guest" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
</form>
<!-- / login form -->
</td>
<td class="navright"></td>
</tr>
</table>

<!-- NAVBAR POPUP MENUS -->

<!-- header quick search form -->


<div class="vbmenu_popup" id="navbar_search_menu" style="display:none" a
lign="left">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">Search Forums</td>
</tr>
<tr>
<td class="vbmenu_option" title="nohilite">
<form action="/forums/googlesearch.php" id="cse-
search-box">
<div>
<input type="hidden" name="cx" value="002919058480771089906:xn_bclo__0i" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" size="20" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cs
e-search-box&lang=en"></script>
</td>
</tr>
<tr>
<td class="vbmenu_option"><a href="http://www.velocityre
views.com/forums/search.php" accesskey="4" rel="nofollow">Advanced Search</a></t
d>
</tr>
</table>
</div>
<!-- / header quick search form -->

<!-- / NAVBAR POPUP MENUS -->


<!-- PAGENAV POPUP -->
<div class="vbmenu_popup" id="pagenav_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead" nowrap="nowrap">Go to Page...</td>
</tr>
<tr>
<td class="vbmenu_option" title="nohilite">
<form action="http://www.velocityreviews.com/forums/inde
x.php" method="get" onSubmit="return this.gotopage()" id="pagenav_form">
<input type="text" class="bginput" id="pagenav_i
txt" style="font-size:11px" size="4" />
<input type="button" class="button" id="pagenav_
ibtn" value="Go" />
</form>
</td>
</tr>
</table>
</div>
<!-- / PAGENAV POPUP -->

<!-- open content container -->


<div align="center">
<div class="page" style="width:100%; text-align:left">
<div style="padding:0px 20px 0px 20px" align="left">
<br />
<span class="navbar"><a href="http://www.velocityreviews.com/forums/index.php">V
elocity Reviews</a>
<span class="navbar">&gt; <a href="http://www.velocityreviews.com/forums
/f16-newsgroups.html">Newsgroups</a></span>

<span class="navbar">&gt; <a href="http://www.velocityreviews.com/forums


/f55-programming.html">Programming</a></span>

<span class="navbar">&gt; <a href="http://www.velocityreviews.com/forums


/f29-asp-net.html">ASP .Net</a></span>
&gt;
Datagrid header text
</span>
<br /><br />
<script type="text/javascript">
<!--
var google_adnum = 0;
var customadstyle = 'table';
google_ad_client = 'pub-9482258749662266';
google_ad_channel ="2683886312";
google_ad_output = 'js';
google_max_num_ads = '3';
google_ad_type = 'text,image,flash,html';
google_image_size = '728x90';
google_feedback = 'on';
google_skip = google_adnum;
// -->
</script>
<script type="text/javascript" src="http://www.velocityreviews.com/forums/client
script/adsense.js"></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/
show_ads.js"></script>

<a name="poststop" id="poststop"></a>


<!-- controls above postbits -->
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-bot
tom:3px">
<tr valign="bottom">
<td class="smallfont"><a href="http://www.velocityreviews.com/fo
rums/newreply.php?do=newreply&amp;noquote=1&amp;p=381694" rel="nofollow"><img sr
c="/forums/images/buttons/reply.gif" alt="Reply" border="0" /></a></td>

</tr>
</table>
<!-- / controls above postbits -->
<!-- toolbar -->
<div class="tcat">
<div class="tcat_right">
<table cellpadding="0" cellspacing="0" style="float:right;">
<tr>
<td class="vbmenu_c" id="threadtools" nowrap="nowrap">
<a rel="nofollow" href="http://www.velocityreviews.com/forums/t8
0435-datagrid-header-text.html?nojs=1#goto_threadtools" accesskey="3">Thread Too
ls</a>
<script type="text/javascript"> vbmenu_register("threadtools");
</script>
</td>
</tr>
</table>
<div class="tcat_left">
<h1>
Datagrid header text
</h1>
</div>
</div>
</div>
<!-- / toolbar -->
<div class="thead" style="height:10px;margin-bottom:2px;">
&nbsp;
</div>

<!-- end content table -->


<!-- / end content table -->

<div id="posts"><!-- post #381694 -->

<div id="edit381694" style="padding:0px 0px 6px 0px">


<!-- this is not the last post shown on the page -->

<table id="post381694" cellpadding="0" cellspacing="0" border="0" width="100%" a


lign="center">
<tr valign="top">
<td class="pbleft" width="179" rowspan="3" align="center" >
<div class="pblefttop">&nbsp;</div>
<div id="postmenu_381694">
Ben
</div>
<div class="smallfont" style="margin-bottom:3px;">Guest<
/div>

<div class="smallfont">Posts: <strong>n/a</strong></div>


<div class="smallfont"></div>
<div> </div>

&nbsp;
<!-- / controls --> </td>
<td id="td_post_381694" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
06-14-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381694" class="KonaBody">
<!-- google_ad_section_start -->
Hi, I'm wondering how can i change the datagrid header text at runtime s
o<br />
that it keeps the sorting enabled?<br />
<br />
I can do;<br />
<br />
e.Item.Cells[0].Text = &quot;foo&quot;;<br />
<br />
But then foo is the text of the table cell and not the underlying hyperlink<br /
>
and as such, foo is no longer sortable.<br />
<br />
I've tried things like...<br />
<br />
((HyperLink)(e.Item.Cells[0].Controls[0]).Text = &quot;foo&quot;;<br />
<br />
But I get a null exception. In fact for some unknown reason,<br />
e.Item.Cells[0].Controls.Count == 0!!!!<br />
<br />
Can someone please show me what it is that I'm doing wrong here?<br />
<br />
Thanks,<br />
Ben<br />
<br />
<br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->

</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop">&nbsp;</div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">

</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">

<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&amp;p=381694" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>

</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>

<!-- post 381694 popup menu -->


<div class="vbmenu_popup" id="postmenu_381694_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">Ben</td>
</tr>
</table>
</div>
<!-- / post 381694 popup menu -->

<div style="padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-


top: 6px" >
<table border="0" cellspacing="0" cellpadding="0" width="100%"
align="center">
<tbody>
<tr valign="top">
<td class="pbleft" rowspan="2" width="200" align="center">
<div class="pblefttop">&nbsp;</div></td>
<td class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table style="margin-bottom: 3px" cellspacing="0" cellpadding="0" width="1
00%"
align="center">
<tbody>
<tr>
<td align="right"></td></tr></tbody></table>

<script type="text/javascript">
<!--
var customadstyle = 'postbit';
google_ad_client = 'pub-9482258749662266';
google_ad_channel ="2683886312";
google_ad_output = 'js';
google_max_num_ads = '3';
google_ad_type = 'text,image,flash,html';
google_image_size = '336x280';
google_feedback = 'on';
google_skip = google_adnum;
// -->
</script>

<script type="text/javascript" src="http://www.velocityreviews.com/forums/client


script/adsense.js"></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/
show_ads.js"></script>
</div>
</td>
<td class="pbright" rowspan="2" width="14" align="center">
<div class="pbrighttop">&nbsp;</div></td></tr>
<tr>
<td style="padding-right: 5px" class="pbmiddle" align="right">&nbsp;</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td></tr></tbody></table></div>

</div>

<!-- / post #381694 --><!-- post #381729 -->

<div id="edit381729" style="padding:0px 0px 6px 0px">


<!-- this is not the last post shown on the page -->

<table id="post381729" cellpadding="0" cellspacing="0" border="0" width="100%" a


lign="center">
<tr valign="top">
<td class="pbleft" width="179" rowspan="3" align="center" >
<div class="pblefttop">&nbsp;</div>
<div id="postmenu_381729">
S. Justin Gengo
</div>
<div class="smallfont" style="margin-bottom:3px;">Guest<
/div>

<div class="smallfont">Posts: <strong>n/a</strong></div>


<div class="smallfont"></div>

<div> </div>

&nbsp;
<!-- / controls --> </td>
<td id="td_post_381729" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
06-14-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381729" class="KonaBody">
<!-- google_ad_section_start -->
Ben,<br />
<br />
I think you'll have to use &quot;FindControl&quot; and then cast the control fou
nd to<br />
the hyperlink.<br />
<br />
--<br />
Sincerely,<br />
<br />
S. Justin Gengo, MCP<br />
Web Developer / Programmer<br />
<br />
<a rel="nofollow" href="http://www.aboutfortunate.com" target="_blank">www.about
fortunate.com</a><br />
<br />
&quot;Out of chaos comes order.&quot;<br />
Nietzsche<br />
&quot;Ben&quot; &lt;&gt; wrote in message<br />
news:01hzc.750$...<font color="blue"><br />
&gt; Hi, I'm wondering how can i change the datagrid header text at runtime so<b
r />
&gt; that it keeps the sorting enabled?<br />
&gt;<br />
&gt; I can do;<br />
&gt;<br />
&gt; e.Item.Cells[0].Text = &quot;foo&quot;;<br />
&gt;<br />
&gt; But then foo is the text of the table cell and not the underlying</font><br
/>
hyperlink<font color="blue"><br />
&gt; and as such, foo is no longer sortable.<br />
&gt;<br />
&gt; I've tried things like...<br />
&gt;<br />
&gt; ((HyperLink)(e.Item.Cells[0].Controls[0]).Text = &quot;foo&quot;;<br />
&gt;<br />
&gt; But I get a null exception. In fact for some unknown reason,<br />
&gt; e.Item.Cells[0].Controls.Count == 0!!!!<br />
&gt;<br />
&gt; Can someone please show me what it is that I'm doing wrong here?<br />
&gt;<br />
&gt; Thanks,<br />
&gt; Ben<br />
&gt;<br />
&gt;<br />
&gt;</font><br />
<br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->

</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop">&nbsp;</div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">

</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">

<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&amp;p=381729" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>

</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>
<!-- post 381729 popup menu -->
<div class="vbmenu_popup" id="postmenu_381729_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">S. Justin Gengo</td>
</tr>

</table>
</div>
<!-- / post 381729 popup menu -->

</div>

<!-- / post #381729 --><!-- post #381891 -->

<div id="edit381891" style="padding:0px 0px 6px 0px">


<!-- this is not the last post shown on the page -->

<table id="post381891" cellpadding="0" cellspacing="0" border="0" width="100%" a


lign="center">
<tr valign="top">
<td class="pbleft" width="179" rowspan="3" align="center" >
<div class="pblefttop">&nbsp;</div>
<div id="postmenu_381891">
Steven Cheng[MSFT]
</div>
<div class="smallfont" style="margin-bottom:3px;">Guest<
/div>

<div class="smallfont">Posts: <strong>n/a</strong></div>


<div class="smallfont"></div>
<div> </div>

&nbsp;
<!-- / controls --> </td>
<td id="td_post_381891" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
06-15-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381891" class="KonaBody">
<!-- google_ad_section_start -->
Hi Ben,<br />
<br />
From your description, you're wondering how to change the DataGrid(has set<br />
columns's sort property) 's header text at runtime and also keep the<br />
datagrid sortable ,yes?<br />
<br />
Based on my research, the Header in the DataGrid in the Asp.net DataGrid<br />
control is represented by a DataGridLinkButton control(is a internal<br />
control hidden from developer) rather than a normal HyperLink or LinkButton<br /
>
control. So we can retrieve it as generally we do. However, I think we can<br />
change the Header's Text by setting the certain DataGrid Column's<br />
HeaderText property since the HeaderText is set for each Column, isn't it?<br />
For example:<br />
<br />
dgMain.Columns[1].HeaderText = &quot;fdsaf&quot;;<br />
<br />
Thus, we can get the proper columns via DataGrid.Columns collection in a<br />
certain postback event and then change its HeaderText , but be care that we<br /
>
have to rebind the DataGrid with datasource after we change the HeaderText<br />
of a column , for example:<br />
<br />
private void btnChangeSortText_Click(object sender, System.EventArgs e)<br />
{<br />
dgMain.Columns[1].HeaderText = &quot;fdsaf&quot;;<br />
Bind_Data();<br />
}<br />
<br />
Hope helps. Thanks.<br />
<br />
<br />
Regards,<br />
<br />
Steven Cheng<br />
Microsoft Online Support<br />
<br />
Get Secure! <a rel="nofollow" href="http://www.microsoft.com/security" target="_
blank">www.microsoft.com/security</a><br />
(This posting is provided &quot;AS IS&quot;, with no warranties, and confers no<
br />
rights.)<br />
<br />
Get Preview at ASP.NET whidbey<br />
<a rel="nofollow" href="http://msdn.microsoft.com/asp.net/whidbey/default.aspx"
target="_blank">http://msdn.microsoft.com/asp.net/whidbey/default.aspx</a><br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->

</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop">&nbsp;</div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">

</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">

<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&amp;p=381891" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>
</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>

<!-- post 381891 popup menu -->


<div class="vbmenu_popup" id="postmenu_381891_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">Steven Cheng[MSFT]</td>
</tr>

</table>
</div>
<!-- / post 381891 popup menu -->

</div>

<!-- / post #381891 --><!-- post #381988 -->

<div id="edit381988" style="padding:0px 0px 6px 0px">

<table id="post381988" cellpadding="0" cellspacing="0" border="0" width="100%" a


lign="center">
<tr valign="top">
<td class="pbleft" width="179" rowspan="3" align="center" >
<div class="pblefttop">&nbsp;</div>
<div id="postmenu_381988">
Ben
</div>
<div class="smallfont" style="margin-bottom:3px;">Guest<
/div>
<div class="smallfont">Posts: <strong>n/a</strong></div>
<div class="smallfont"></div>

<div> </div>

&nbsp;
<!-- / controls --> </td>
<td id="td_post_381988" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
06-15-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381988" class="KonaBody">
<!-- google_ad_section_start -->
After doing some research it looks like a good place to do this is in th
e<br />
ItemCreated event of the datagrid. The one catch is that the itemcreated<br />
fires in the viewstate init function. Which I thought was odd.<br />
<br />
Nevertheless, here is what I ended up doing...<br />
<br />
<br />
private void dgSubordinate_ItemCreated(object sender,<br />
System.Web.UI.WebControls.DataGridItemEventArgs e)<br />
{<br />
if (e.Item.ItemType != ListItemType.Header) return;<br />
<br />
string HeaderText = null;<br />
<br />
if (oSecurity != null)<br />
{<br />
switch (oSecurity.ReportType)<br />
{<br />
case SecurityPermissions.Regional:<br />
HeaderText = &quot;SVP&quot;;<br />
break;<br />
case SecurityPermissions.SVP:<br />
HeaderText = &quot;VP&quot;;<br />
break;<br />
case SecurityPermissions.VP:<br />
HeaderText = &quot;AE&quot;;<br />
break;<br />
}<br />
((LinkButton)e.Item.Cells[0].Controls[0]).Text = HeaderText;<br />
}<br />
}<br />
<br />
<br />
So, that's working just fine. I ended up needing the oSecurity != null<br />
check becuase of the fact that the ItemCreate is fired in the<br />
viewstateinit(or whatever its called). Since my security object doesn't<br />
exist until Page_Load, I needed the null check. At some point I'll look<br />
into the initilization of the datagrid and see why it's creating items so<br />
early, but I can guess. Anyway, thanks for your help.<br />
<br />
<br />
&quot;Steven Cheng[MSFT]&quot; &lt;v-&gt; wrote in message<br />
news:...<font color="blue"><br />
&gt; Hi Ben,<br />
&gt;<br />
&gt; From your description, you're wondering how to change the DataGrid(has set<
br />
&gt; columns's sort property) 's header text at runtime and also keep the<br />
&gt; datagrid sortable ,yes?<br />
&gt;<br />
&gt; Based on my research, the Header in the DataGrid in the Asp.net DataGrid<b
r />
&gt; control is represented by a DataGridLinkButton control(is a internal<br />
&gt; control hidden from developer) rather than a normal HyperLink or</font><br
/>
LinkButton<font color="blue"><br />
&gt; control. So we can retrieve it as generally we do. However, I think we can<
br />
&gt; change the Header's Text by setting the certain DataGrid Column's<br />
&gt; HeaderText property since the HeaderText is set for each Column, isn't it?<
br />
&gt; For example:<br />
&gt;<br />
&gt; dgMain.Columns[1].HeaderText = &quot;fdsaf&quot;;<br />
&gt;<br />
&gt; Thus, we can get the proper columns via DataGrid.Columns collection in a<br
/>
&gt; certain postback event and then change its HeaderText , but be care that</f
ont><br />
we<font color="blue"><br />
&gt; have to rebind the DataGrid with datasource after we change the HeaderText<
br />
&gt; of a column , for example:<br />
&gt;<br />
&gt; private void btnChangeSortText_Click(object sender, System.EventArgs e)<br
/>
&gt; {<br />
&gt; dgMain.Columns[1].HeaderText = &quot;fdsaf&quot;;<br />
&gt; Bind_Data();<br />
&gt; }<br />
&gt;<br />
&gt; Hope helps. Thanks.<br />
&gt;<br />
&gt;<br />
&gt; Regards,<br />
&gt;<br />
&gt; Steven Cheng<br />
&gt; Microsoft Online Support<br />
&gt;<br />
&gt; Get Secure! <a rel="nofollow" href="http://www.microsoft.com/security" targ
et="_blank">www.microsoft.com/security</a><br />
&gt; (This posting is provided &quot;AS IS&quot;, with no warranties, and confer
s no<br />
&gt; rights.)<br />
&gt;<br />
&gt; Get Preview at ASP.NET whidbey<br />
&gt; <a rel="nofollow" href="http://msdn.microsoft.com/asp.net/whidbey/default.a
spx" target="_blank">http://msdn.microsoft.com/asp.net/whidbey/default.aspx</a><
br />
&gt;</font><br />
<br />
<br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->

</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop">&nbsp;</div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">

</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">

<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&amp;p=381988" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>
</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>

<!-- post 381988 popup menu -->


<div class="vbmenu_popup" id="postmenu_381988_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">Ben</td>
</tr>

</table>
</div>
<!-- / post 381988 popup menu -->

<div style="padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-


top: 6px" >
<table border="0" cellspacing="0" cellpadding="0" width="100%"
align="center">
<tbody>
<tr valign="top">
<td class="pbleft" rowspan="2" width="200" align="center">
<div class="pblefttop">&nbsp;</div></td>
<td class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table style="margin-bottom: 3px" cellspacing="0" cellpadding="0" width="1
00%"
align="center">
<tbody>
<tr>
<td align="right"></td></tr></tbody></table>
<script type="text/javascript">
<!--
var customadstyle = 'postbit';
google_ad_client = 'pub-9482258749662266';
google_ad_channel ="2683886312";
google_ad_output = 'js';
google_max_num_ads = '3';
google_ad_type = 'text';
google_image_size = '336x280';
google_feedback = 'on';
google_skip = google_adnum;
// -->
</script>

<script type="text/javascript" src="http://www.velocityreviews.com/forums/client


script/adsense.js"></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/
show_ads.js"></script>
</div>

</td>
<td class="pbright" rowspan="2" width="14" align="center">
<div class="pbrighttop">&nbsp;</div></td></tr>
<tr>
<td style="padding-right: 5px" class="pbmiddle" align="right">&nbsp;</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td></tr></tbody></table></div>

</div>

<!-- / post #381988 --><div id="lastpost"></div></div>


<!-- start content table -->
<!-- / start content table -->

<!-- controls below postbits -->


<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-top
:-3px">
<tr valign="top">
<td class="smallfont"><a href="http://www.velocityreviews.com/fo
rums/newreply.php?do=newreply&amp;noquote=1&amp;p=381988" rel="nofollow"><img sr
c="/forums/images/buttons/reply.gif" alt="Reply" border="0" /></a></td>

</tr>
</table>
<!-- / controls below postbits -->
<!-- lightbox scripts -->
<script type="text/javascript" src="clientscript/vbulletin_lightbox.js?v
=386"></script>
<script type="text/javascript">
<!--
vBulletin.register_control("vB_Lightbox_Container", "posts", 1);
//-->
</script>
<!-- / lightbox scripts -->

<!-- next / previous links -->


<br /><div class="navbar">
<div class="smallfont" align="center">
<strong>&laquo;</strong>
<a href="http://www.velocityreviews.com/forums/t80540-sc
ope-of-variables-declared-in-vb-module-files.html" >Scope of variables declared
in .vb module files</a>
|
<a href="http://www.velocityreviews.com/forums/t80472-wr
iteto-csv-file.html" >writeto csv file</a>
<strong>&raquo;</strong>
</div></div>
<!-- / next / previous links -->

<!-- popup menu contents -->


<br />
<!-- thread tools menu -->
<div class="vbmenu_popup" id="threadtools_menu" style="display:none">
<form action="http://www.velocityreviews.com/forums/postings.php?t=80435&amp;pol
lid=" method="post" name="threadadminform">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">Thread Tools<a name="goto_threadtools"></a></t
d>
</tr>
<tr>
<td class="vbmenu_option"><img class="inlineimg" src="/forums/im
ages/buttons/printer.gif" alt="Show Printable Version" /> <a href="http://www.ve
locityreviews.com/forums/printthread.php?t=80435" accesskey="3" rel="nofollow">S
how Printable Version</a></td>
</tr>
<tr>
<td class="vbmenu_option"><img class="inlineimg" src="/forums/im
ages/buttons/sendtofriend.gif" alt="Email this Page" /> <a href="http://www.velo
cityreviews.com/forums/sendmessage.php?do=sendtofriend&amp;t=80435" rel="nofollo
w">Email this Page</a></td>
</tr>

</table>
</form>
</div>
<!-- / thread tools menu -->
<!-- **************************************************** -->

<!-- **************************************************** -->

<!-- / popup menu contents -->

<!-- forum rules and admin links -->


<table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr valign="bottom">
<td width="100%" valign="top">
<table class="tborder" cellpadding="6" cellspacing="0" border="0
" width="210">
<thead>
<tr>
<td class="thead">
<a style="float:right" href="#top" onclick="return toggle_collap
se('forumrules')"><img id="collapseimg_forumrules" src="/forums/images/buttons/c
ollapse_thead.gif" alt="" border="0" /></a>
Posting Rules
</td>
</tr>
</thead>
<tbody id="collapseobj_forumrules" style="">
<tr>
<td class="alt1" nowrap="nowrap"><div class="smallfont">
<div>You <strong>may not</strong> post new threads</div>
<div>You <strong>may not</strong> post replies</div>
<div>You <strong>may not</strong> post attachments</div>
<div>You <strong>may not</strong> edit your posts</div>
<hr />
<div><a rel="nofollow" href="http://www.velocityreviews.com/foru
ms/misc.php?do=bbcode" target="_blank">BB code</a> is <strong>On</strong></div>
<div><a rel="nofollow" href="http://www.velocityreviews.com/foru
ms/misc.php?do=showsmilies" target="_blank">Smilies</a> are <strong>On</strong><
/div>
<div><a rel="nofollow" href="http://www.velocityreviews.com/foru
ms/misc.php?do=bbcode#imgcode" target="_blank">[IMG]</a> code is <strong>On</str
ong></div>
<div>HTML code is <strong>Off</strong></div><div><a rel="nofollo
w" href="http://www.velocityreviews.com/forums/misc.php?do=linkbacks#trackbacks"
target="_blank">Trackbacks</a> are <strong>Off</strong></div>
<div><a rel="nofollow" href="http://www.velocityreviews.com/forums/misc.php?do=l
inkbacks#pingbacks" target="_blank">Pingbacks</a> are <strong>Off</strong></div>
<div><a rel="nofollow" href="http://www.velocityreviews.com/forums/misc.php?do=l
inkbacks#refbacks" target="_blank">Refbacks</a> are <strong>Off</strong></div>
<hr />
<div><a rel="nofollow" href="http://www.velocityreviews.com/foru
ms/misc.php?do=showrules" target="_blank">Forum Rules</a></div>
</div></td>
</tr>
</tbody>
</table>
</td>
<td class="smallfont" align="right">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /forum rules and admin links -->
<br />
<table class="tborder" cellpadding="6" cellspacing="0" border="0" width="100%" a
lign="center">
<thead>
<tr>
<td class="tcat" width="100%" colspan="5">
<a style="float:right" href="#top" onclick="return toggl
e_collapse('similarthreads')"><img id="collapseimg_similarthreads" src="/forums/
images/buttons/collapse_tcat.gif" alt="" border="0" /></a>
Similar Threads<a name="similarthreads"></a>
</td>
</tr>
</thead>
<tbody id="collapseobj_similarthreads" style="">
<tr class="thead" align="center">
<td class="thead" width="40%">Thread</td>
<td class="thead" width="15%" nowrap="nowrap">Thread Starter</td>
<td class="thead" width="20%">Forum</td>
<td class="thead" width="5%">Replies</td>
<td class="thead" width="20%">Last Post</td>
</tr>
<tr>
<td class="alt1" align="left">
<span class="smallfont"> <a href="http://www.velocityreviews.com
/forums/t618401-datagrid-linefeed-in-header-text.html" title="How can I put a li
nefeed in some header text (I am using the Datagrid
control and editing the header properties for a field)?
Average Sales ...">Datagrid - Linefeed in header text</a></span>
</td>
<td class="alt2" nowrap="nowrap"><span class="smallfont">Mark B</span></
td>
<td class="alt1" nowrap="nowrap"><span class="smallfont">ASP .Net</span>
</td>
<td class="alt2" align="center"><span class="smallfont">4</span></td>
<td class="alt1" align="right"><span class="smallfont">06-04-2008 <span
class="time">01:34 PM</span></span></td>
</tr>
<tr>
<td class="alt1" align="left">
<span class="smallfont"> <a href="http://www.velocityreviews.com
/forums/t111796-setting-header-text-for-a-datagrid.html" title="I am having a ha
rd time figuring out how to set header text for a
datagrid - I have found a number of pages on it but none work. Some
seem to be...">setting header text for a datagrid?</a></span>
</td>
<td class="alt2" nowrap="nowrap"><span class="smallfont">Mad Scientist J
r</span></td>
<td class="alt1" nowrap="nowrap"><span class="smallfont">ASP .Net</span>
</td>
<td class="alt2" align="center"><span class="smallfont">1</span></td>
<td class="alt1" align="right"><span class="smallfont">10-18-2005 <span
class="time">05:01 PM</span></span></td>
</tr>
<tr>
<td class="alt1" align="left">
<span class="smallfont"> <a href="http://www.velocityreviews.com
/forums/t98149-changing-datagrid-header-text.html" title="Hi all,
I have problem with datagrid in asp.net using vb as the
language. This is how I show the datagrid from database
datagrid1.datasource =...">Changing datagrid header text</a></span>
</td>
<td class="alt2" nowrap="nowrap"><span class="smallfont">Herry</span></t
d>
<td class="alt1" nowrap="nowrap"><span class="smallfont">ASP .Net</span>
</td>
<td class="alt2" align="center"><span class="smallfont">2</span></td>
<td class="alt1" align="right"><span class="smallfont">03-08-2005 <span
class="time">07:50 AM</span></span></td>
</tr>
<tr>
<td class="alt1" align="left">
<span class="smallfont"> <a href="http://www.velocityreviews.com
/forums/t94332-how-do-i-change-the-header-text-in-a-datagrid-that-is-databound.h
tml" title="Hi,
I have tried aliasing columns in the SELECT statement - they get ignored.
I have tried accessing the .columns(0).headertext - but as the grid...">How do i
: Change the header text in a datagrid that is databound?</a></span>
</td>
<td class="alt2" nowrap="nowrap"><span class="smallfont">John Blair</spa
n></td>
<td class="alt1" nowrap="nowrap"><span class="smallfont">ASP .Net</span>
</td>
<td class="alt2" align="center"><span class="smallfont">2</span></td>
<td class="alt1" align="right"><span class="smallfont">01-12-2005 <span
class="time">11:35 AM</span></span></td>
</tr>
<tr>
<td class="alt1" align="left">
<span class="smallfont"> <a href="http://www.velocityreviews.com
/forums/t76442-datagrid-column-header-text.html" title="I have a web form with a
datagrid. The datagrid has 5 columns. In design
mode each column has header text. I defined the header text, data source,...">Da
tagrid Column Header Text</a></span>
</td>
<td class="alt2" nowrap="nowrap"><span class="smallfont">Demetri</span><
/td>
<td class="alt1" nowrap="nowrap"><span class="smallfont">ASP .Net</span>
</td>
<td class="alt2" align="center"><span class="smallfont">0</span></td>
<td class="alt1" align="right"><span class="smallfont">04-21-2004 <span
class="time">07:03 PM</span></span></td>
</tr>
</tbody>
</table>
<br />

<br />
<img src="http://www.velocityreviews.com/forums/cron.php?rand=1304399700
" alt="" width="1" height="1" border="0" />

</div>
</div>
</div>
<!-- / close content container -->
<!-- /content area table -->

<table cellpadding="0" cellspacing="0" border="0" align="center" class="


navigation" width="100%">
<tr align="center">
<td class="navleft"></td>
<td width="33%"></td>
<td width="33%" style="white-space: nowrap"><div class="footertext">
Powered by vBulletin&reg; Version 3.8.6<br />Copyright &copy;2000 - 2011, Jelsof
t Enterprises Ltd..
<br />SEO by vBSEO 3.5.2 &copy;2010, Crawlability, Inc.</div></td>
<td width="33%" align="right"><div class="footertext">
<strong>
<a href="http://www.velocityreviews.com/forums/s
endmessage.php" rel="nofollow" accesskey="9">Contact Us</a> -
<a href="http://www.velocityreviews.com/forums/a
rchive/">Archive</a> -
<a rel="nofollow" href="http://www.velocityrevie
ws.com/forums/faq.php?faq=privacypolicy">Privacy Statement</a> -
<a href="#top" onclick="self.scrollTo(0, 0); return fals
e;">Top</a> </strong>
</div></td>
<td class="navright"></td>
</tr>
</table>

<script type="text/javascript">
<!--
// Main vBulletin Javascript Initialization
vBulletin_init();
//-->
</script>

<div class="topadvert">
<script type="text/javascript"><!--
e9 = new Object();
e9.size = "728x90,468x60";
e9.noAd = 1;
//--></script>
<script type="text/javascript" src="http://tags.expo9.exponential.com/tags/Veloc
ityReviewscom/ROS/tags.js"></script>
</div>

<!-- temp -->


<div style="display:none">
<!-- thread rate -->

<!-- / thread rate -->


</div>

<!-- start Vibrant Media IntelliTXT script section -->


<script type="text/javascript" src="http://velocityreviews.uk.intellitxt.com/int
ellitxt/front.asp?ipid=26675"></script>
<!-- end Vibrant Media IntelliTXT script section -->

<script type="text/javascript">
var vglnk = { api_url: '//api.viglink.com/api',
key: 'a1b43bb7c89550212cc6e8e52d78e22a' };
(function(d, t) {
var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;
s.src = ('https:' == document.location.protocol ? vglnk.api_url :
'//cdn.viglink.com/api') + '/vglnk.js';
var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r);
}(document, 'script'));
</script>
<br /><div style="z-index:3" class="smallfont" align="center"><a href="http://ww
w.velocityreviews.com/forums/archive/f-3.html">1</a> <a href="http://www.velocit
yreviews.com/forums/archive/f-10.html">2</a> <a href="http://www.velocityreviews
.com/forums/archive/f-11.html">3</a> <a href="http://www.velocityreviews.com/for
ums/archive/f-14.html">4</a> <a href="http://www.velocityreviews.com/forums/arch
ive/f-9.html">5</a> <a href="http://www.velocityreviews.com/forums/archive/f-1.h
tml">6</a> <a href="http://www.velocityreviews.com/forums/archive/f-44.html">7</
a> <a href="http://www.velocityreviews.com/forums/archive/f-5.html">8</a> <a hre
f="http://www.velocityreviews.com/forums/archive/f-6.html">9</a> <a href="http:/
/www.velocityreviews.com/forums/archive/f-13.html">10</a> <a href="http://www.ve
locityreviews.com/forums/archive/f-7.html">11</a> <a href="http://www.velocityre
views.com/forums/archive/f-22.html">12</a> <a href="http://www.velocityreviews.c
om/forums/archive/f-23.html">13</a> <a href="http://www.velocityreviews.com/foru
ms/archive/f-16.html">14</a> <a href="http://www.velocityreviews.com/forums/arch
ive/f-57.html">15</a> <a href="http://www.velocityreviews.com/forums/archive/f-3
3.html">16</a> <a href="http://www.velocityreviews.com/forums/archive/f-41.html"
>17</a> <a href="http://www.velocityreviews.com/forums/archive/f-38.html">18</a>
<a href="http://www.velocityreviews.com/forums/archive/f-46.html">19</a> <a hre
f="http://www.velocityreviews.com/forums/archive/f-19.html">20</a> <a href="http
://www.velocityreviews.com/forums/archive/f-34.html">21</a> <a href="http://www.
velocityreviews.com/forums/archive/f-35.html">22</a> <a href="http://www.velocit
yreviews.com/forums/archive/f-37.html">23</a> <a href="http://www.velocityreview
s.com/forums/archive/f-40.html">24</a> <a href="http://www.velocityreviews.com/f
orums/archive/f-20.html">25</a> <a href="http://www.velocityreviews.com/forums/a
rchive/f-27.html">26</a> <a href="http://www.velocityreviews.com/forums/archive/
f-47.html">27</a> <a href="http://www.velocityreviews.com/forums/archive/f-56.ht
ml">28</a> <a href="http://www.velocityreviews.com/forums/archive/f-24.html">29<
/a> <a href="http://www.velocityreviews.com/forums/archive/f-25.html">30</a> <a
href="http://www.velocityreviews.com/forums/archive/f-26.html">31</a> <a href="h
ttp://www.velocityreviews.com/forums/archive/f-48.html">32</a> <a href="http://w
ww.velocityreviews.com/forums/archive/f-49.html">33</a> <a href="http://www.velo
cityreviews.com/forums/archive/f-50.html">34</a> <a href="http://www.velocityrev
iews.com/forums/archive/f-52.html">35</a> <a href="http://www.velocityreviews.co
m/forums/archive/f-53.html">36</a> <a href="http://www.velocityreviews.com/forum
s/archive/f-51.html">37</a> <a href="http://www.velocityreviews.com/forums/archi
ve/f-55.html">38</a> <a href="http://www.velocityreviews.com/forums/archive/f-42
.html">39</a> <a href="http://www.velocityreviews.com/forums/archive/f-43.html">
40</a> <a href="http://www.velocityreviews.com/forums/archive/f-39.html">41</a>
<a href="http://www.velocityreviews.com/forums/archive/f-29.html">42</a> <a href
="http://www.velocityreviews.com/forums/archive/f-30.html">43</a> <a href="http:
//www.velocityreviews.com/forums/archive/f-31.html">44</a> <a href="http://www.v
elocityreviews.com/forums/archive/f-32.html">45</a> <a href="http://www.velocity
reviews.com/forums/archive/f-18.html">46</a> <a href="http://www.velocityreviews
.com/forums/archive/f-17.html">47</a> </div>
<script type="text/javascript">
//<![CDATA[
window.orig_onload = window.onload;
window.onload = function() {
var cpost=document.location.hash.substring(1);var cpost2='';if(cpost){ var ispos
t=cpost.substring(0,4)=='post';if(ispost)cpost2='post_'+cpost.substring(4);if((c
obj = fetch_object(cpost))||(cobj = fetch_object(cpost2))){cobj.scrollIntoView(t
rue);}else if(ispost){cpostno = cpost.substring(4,cpost.length);if(parseInt(cpos
tno)>0){location.replace('http://www.velocityreviews.com/forums/showthread.php?p
='+cpostno);};} }
if(typeof window.orig_onload == "function") window.orig_onload();
}
//]]>
</script>
</body>
</html>

Potrebbero piacerti anche