Nested Master pages image showing problem in webpages

Filed in .Net Leave a comment

Today I am handling Master and Nester master first time I found it very useful. I am having pay for someone to write your essay problem in showing master page images in my content web pages.

I need to set two things this;

  1. Make all image as runat=”server”
  2. Image src path should be give with Tilda sign “~” for e.g src=”~/images/HeaderAdmin.jpg”

In my senario my Main master page “MainMP.master” and admin site master page is “AdminMP.master” on root folder of website whereas content web pages of Admin side are in a sub folder “root\Admin\pagename.aspx”.

An e.g is below and important things are in bold;

Main Master Page

<%@ Master Language=”C#” AutoEventWireup=”true” CodeFile=”MainMP.master.cs” Inherits=”Main” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>ProGold Network</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table width=”100%”>
<tr>
<td colspan=”3″>
<img id=”imgHeader” alt=” Hi Master and Nester Master Page testing” src=”~/images/HeaderAdmin.jpg” runat=”server” />
</td>
</tr>
<tr>
<td colspan=”3″>
<asp:ContentPlaceHolder ID=”MainContent” runat=”server”>
</asp:ContentPlaceHolder>
</td>
</tr>
<tr>
<td>
Footer
</td>
<td style=”text-align: right;”>
<img src=”~/images/bbb.jpg” runat=”server” alt=”" width=”56″ height=”54″ />
<img src=”~/images/verisign.jpg” runat=”server” alt=”" width=”77″ height=”57″ />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Nested Master Page

<%@ Master Language=”C#” MasterPageFile=”~/MainMP.master” AutoEventWireup=”true” CodeFile=”AdminMP.master.cs”  Inherits=”Admin_AdminMP” %>

<asp:Content ID=”Content2″ ContentPlaceHolderID=”MainContent” runat=”Server”>
<tr>
<td>
<table>
<tr>
<td colspan=”10″ align=”center”>
Search FedEx No.:
<asp:TextBox runat=”server” ID=”TextBox2″></asp:TextBox>
&nbsp;
<asp:Button runat=”server” Text=”Search” ID=”Button2″></asp:Button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:ContentPlaceHolder ID=”PageContent” runat=”server”>
</asp:ContentPlaceHolder>
</td>
</tr>
</asp:Content>

Content WebPage

<asp:Content ID=”Content2″ ContentPlaceHolderID=”PageContent” runat=”Server”>
<table width=”100%”>
<tr>
<td>
<asp:Label ID=”lblMsg” runat=”server” Text=”"></asp:Label>
</td>
</tr>
</table>
</asp:Content>

Show gridview header if no record in datatable

Filed in .Net Leave a comment

I found no good solution for it. Simple work around not solution is left girdview without header and set your message “Not record found” in gridview property “EmptyDataText”

Some other work around are listed below from different site.

From MSDN

<asp:GridView ID=”CustomersGridView” DataSourceID=”CustomersSqlDataSource” AutoGenerateColumns=”true”

runat=”server”>

<EmptyDataRowStyle BackColor=”LightBlue” ForeColor=”Red” />

<EmptyDataTemplate>

<asp:Image ID=”NoDataImage” ImageUrl=”~/images/Image.jpg” AlternateText=”No Image”

runat=”server” />

No Data Found.

</EmptyDataTemplate>

</asp:GridView>

From another forum almost similar

Getting values from GridView Bound, Template and DataKeys Columns on RowCommand Event

Filed in .Net Leave a comment

I have a button field on my GridView on the click of that button I need to pick the values for that particular row.

1. First I need to define CommandName for the button in GridView from design view of page.

<asp:ButtonField ButtonType=”Button” Text=”Send” CommandName=”Send” />

2. For writing code I have selected RowCommand Event of the GirdView.

protected void gvnewProRequests_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == “Send”)
{
int intindex = Convert.ToInt32(e.CommandArgument);
GridViewRow gvrselectedRow = gvnewProRequests.Rows[intindex];

//Form bound columns
int intPOId = Convert.ToInt32(Server.HtmlDecode(gvrselectedRow.Cells[0].Text));
//I am not able to find any solution for getting cell values by name thats why using index

//From DataKeys
int intSellerId = Convert.ToInt32(gvnewProRequests.DataKeys[intindex].Values["SId"]);

//From Template columns Textbox
string strprokNo = ((TextBox)gvrselectedRow.FindControl(“txtgvProNo”)).Text;
}
}

DataKeys are very useful as hidden columns you can easily define any columns of your datatable whcih is bind to your GirdView as DataKey column by adding tag DataKeyNames in GridView design mode, you can also define muliple columns as shown below

<asp:GridView runat=”server” ID=”gvnewProRequests” AutoGenerateColumns=”False” OnRowCommand=”gvnewProKitRequests_RowCommand” DataKeyNames=”ProKitStatusId,SId”>

,

TOP