I have a page in my website which shows up a map and there is a dropdown and on clicking the options in the dropdown, it would show up different pins in different locations. This part is working fine, which I have been able to do through response.redirect() by reloading the sections having different pins in the same page.
Now below this map, I do have a gridview which should populate the location addresses and contacts on change of dropdown options. But unfortunately, gridview is not showing up, but I have checked while debugging, that it's populating data.
Here is my aspx gridview code (which has visibility set to false, so that it doesn't show up until and unless and option is selected in the map dropdown) :
<asp:GridView ID="grdMapData" runat="server" class="table table-striped" AlternatingRowStyle-BackColor="#eaeaea" ShowHeader="true"
EmptyDataRowStyle-HorizontalAlign="Center" EmptyDataRowStyle-ForeColor="Red" OnRowCreated="grdMapData_RowCreated"
OnRowDataBound="grdMapData_RowDataBound" ShowHeaderWhenEmpty="true" EmptyDataText="No Data Found !!"
AutoGenerateColumns="false" Visible="false">
<Columns>
<asp:TemplateField HeaderText="Sl. No" ItemStyle-Width="4%" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="gridHeader" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="gridRow">
<ItemTemplate>
<asp:Label ID="lblSno" runat="server" Enabled="false" Text="<%#Container.DataItemIndex+1%>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="District Name" ItemStyle-Width="20%"
ItemStyle-CssClass="gridRow" HeaderStyle-HorizontalAlign="Center" HeaderStyle-CssClass="gridHeader"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblDistName" runat="server" CssClass="required" Text='<%#Eval("DSM_DISTRICT_DESCRIPTION") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" ItemStyle-Width="30%"
ItemStyle-CssClass="gridRow" HeaderStyle-HorizontalAlign="Center" HeaderStyle-CssClass="gridHeader"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblAddress" runat="server" CssClass="required" Text='<%#Eval("ADDRESS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Map points code in the front example (please note that there is no other way to display the map points, other than href in html but href doesn't work with asp dropdownlist) :
<section id="gm_offices_id">
<!-- chittoor -->
<div id="chittoor" class="msme_ap_map_icon msme_ap_map_icon_chittor" runat="server">
<img src="../Assets/Images/location_icon.svg" alt="" id="img-chitoor">
<div id="box-chi" class="district_box">
<p>District Industries Centre - Chittoor</p>
<p>
House no.113, SBI COLONY 2nd Street, Puttur road, Chittoor, 517001
</p>
</div>
</div>
<!-- tirupati -->
<div id="tirupati_1" class="msme_ap_map_icon msme_ap_map_icon_tirupati">
<img src="../Assets/Images/location_icon.svg" alt="" id="img-tirupati">
<div id="box-chi" class="district_box">
<p>District Industries Centre - Tirupati</p>
<p>
Room No, 506 to 514, A-Block, Collectorate, Tirupati
</p>
</div>
</div>
</section>
Here is the code which gets invoked on dropdown selection :
protected void ddlCategory_OnSelectedIndexChanged(object sender, EventArgs e)
{
if(ddlMapCategory.SelectedValue == "DIC")
{
Response.Redirect("AP_State_Map.aspx#gm_offices_id", false);
bindMapData(ddlMapCategory.SelectedValue);
grdMapData.Visible = true;
}
else if (ddlMapCategory.SelectedValue == "MSME-PARKS")
{
Response.Redirect("AP_State_Map.aspx#msme_parks", false);
bindMapData(ddlMapCategory.SelectedValue);
grdMapData.Visible = true;
}
else if (ddlMapCategory.SelectedValue == "ID")
{
Response.Redirect("AP_State_Map.aspx#id_project", false);
bindMapData(ddlMapCategory.SelectedValue);
grdMapData.Visible = true;
}
else
{
Response.Redirect("AP_State_Map.aspx#clusters_id", false);
bindMapData(ddlMapCategory.SelectedValue);
grdMapData.Visible = true;
}
}
Gridview bind data method:
protected void bindMapData(string mapCat)
{
grdMapData.Visible = true;
DataTable l_dt = new DataTable();
object[] obj = { mapCat, null };
DataSet ds = objBO.Get_MSME_Map_Data(obj);
DataTable dt = ds.Tables[0];
grdMapData.DataSource = dt;
grdMapData.DataBind();
}
Also I would like to let you know that this is on the public side of the website without any logins and we don't capture any user data to access this. And sorry for my English. Thanks in advance for helping me out.
Once you redirect the user, the page is gone. They've now navigated to a new page. Whatever data you're trying to show the user, show it on that page. (Even if it's "the same page", it's an entirely new navigation to that URL.)
You'll want to bind that data in the Page_Load
handler when loading AP_State_Map.aspx
. You can know which data to bind by sending that value on the query string. For example:
Response.Redirect("AP_State_Map.aspx?value=DIC#gm_offices_id", false);
When in Page_Load
you'd get that value from the query string:
var selectedValue = Request.QueryString["value"];
bindMapData(selectedValue);
grdMapData.Visible = true;
In that same Page_Load
logic you'd also want to handle what to do when the specified value is empty or not a value supported in the logic.