How to hide two GridView columns after all rows are created and databound without losing the data.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
There is a ScriptManager.RegisterStartupScript which runs and allows me to see and utilize the data string to create multiple map markers before first map presentation (Thanks to Anze J.) There is also a GridView row button that sets off create marker data also. Problem is now the users do not want to see two column fields that contain the data needed to create the multiple map markers and needed to create single row marker . If I make the column not visible it loses all the markers. Making the column width 1px does not work. Attempts to apply HTML hide code on the BoundField GridView line does not hide anything.
Is there any way to hide the column after everything is built just before the GridView and Map are shown? If so where would I put the code? How could I un-hide the two columns when a new map is to be created so data is there, and then hide it again just before GridView and Map are shown as new again?
ASPX code is:
<script type = "text/javascript
var map = null;
function _createPinFor(pinData) {
if (map == null) {
map = new GMap2(document.getElementById(map));
}
vlon = pinData.vYcoord
vlat = pinData.vXcoord
if (vlat < "00.000000" && vlon > "00.000000")
{
var marker = new GMarker(new GLatLng(vlon, vlat));
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(pinData.vLocation + <br> + pinData.vType);
}); -
map.addOverlay(marker);
return false;
}
return false;
}
function loadEarth() {
if (map == null) {
map = new GMap2(document.getElementById(map));
}
map.setCenter(new GLatLng(39.099160, -77.654114), 10);
map.setUIToDefault();
}
function GetSelectedRow(lnk)
{
var row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
var vcalldate = row.cells[0].innerHTML;
var vLocation = row.cells[2].innerHTML;
var vType = row.cells[3].innerHTML;
var vXcoord = row.cells[4].innerHTML;
var vYcoord = row.cells[5].innerHTML;
vlon = vYcoord
if (vlat < "00.000000" && vlon > "00.000000")
{
var marker = new GMarker(new GLatLng(vlon, vlat));
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(vLocation + <br> + vType);
}); -
map.addOverlay(marker);
marker.openInfoWindowHtml(vLocation + <br> + vType);
return false;
}
return false;
}
</script>
</head>
<body onload="loadEarth();
<form id="form1" runat="server
<asp:ScriptManager ID="ScriptManager1" runat="server </asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="InNum"
horizontalalign="Center"
EmptyDataText="There are no current investigations reported." Width="800px"
DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged1"
OnRowDataBound="GridView_RowDataBound" CellPadding="4"
Font-Bold="True" Font-Size="Large" ForeColor="#333333" BorderStyle="Solid"
BorderWidth="1px
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EmptyDataRowStyle CssClass="MessageTitleText" />
<Columns>
<asp:BoundField DataField="CallDate" HeaderText="Date"
SortExpression="CallDate" />
<asp:BoundField DataField="CallTime" HeaderText="Time"
SortExpression="CallTime" ReadOnly="True" />
<asp:BoundField DataField="Address" HeaderText="Location"
SortExpression="Address" />
<asp:BoundField DataField="Type" HeaderText="Type"
SortExpression="Type" ReadOnly="True" />
<asp:BoundField DataField="Xcoord" HeaderText="Xcoord"
SortExpression="Xcoord" ReadOnly="True" ShowHeader="False" />
<asp:BoundField DataField="Ycoord" HeaderText="Ycoord"
SortExpression="Ycoord" ReadOnly="True" ShowHeader="False" />
<asp:TemplateField ShowHeader="False
<ItemTemplate>
<asp:Button ID="bLocate" runat="server" Text="Locate" OnClientClick = "return GetSelectedRow(this)" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" Font-Size="Larger"
ForeColor="White" />
<EditRowStyle BackColor="#2461BF" BorderStyle="Solid" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<div id="Panel" align="center
<a id="LinkToMobile m/mdefault.aspx" target="_blank" style="color:Blue; Switch to Mobile Device View
<asp:Button ID="bClearMap2" runat="server" Text="Clear the Map" OnClientClick = "return loadEarth()" />
<span id="ErrorLabel" style="font-weight: 700; color: #FF0000; font-family: Arial, Helvetica, sans-serif;
<br />

<br />
<div style="height: auto; padding-bottom: 25px;
<div id="map" style="width: 800px; height: 450px" align="center
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [InNum], [CallDate], [CallTime], [Address], [Xcoord], [Ycoord], [Type] FROM [V_Traffic]
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT COUNT(*) AS [CountRecords]FROM [V_Traffic]
</asp:SqlDataSource>

partial ASPX.CS code is:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ScriptManager.RegisterStartupScript(
this,
this.GetType(),
Guid.NewGuid().ToString(),
string.Format(@"_createPinFor({{
vcalldate: ""{0}"",
vLocation: ""{1}"",
vType: ""{2}"",
vXcoord: ""{3}"",
vYcoord: ""{4}""
}});",
e.Row.Cells[0].Text,
e.Row.Cells[2].Text,
e.Row.Cells[3].Text,
e.Row.Cells[4].Text,
e.Row.Cells[5].Text),
true // auto add script tags
);

View the full article
 
Back
Top