Friday, 8 November 2013
Get RSS Feed to your Website
Hi,
Today I have Implemented this simple method to get the RSS feed from any other website. Usually this is used to get the Daily/Breaking/Latest News to your website.
So, Now i am going to explain how we can achieve this via simple coding.
<marquee behavious="scroll" direction="up" scrollamount="4" onmouseover="this.stop()" onmouseout="this.start()">
<div style=" text-justify: inter-word; text-align: justify">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1" >
<ItemTemplate>
<a target="_blank" href='<%# XPath("link") %>'>
<%# System.Web.HttpUtility.HtmlEncode(XPath("title").ToString())%></a>
<br />
<asp:Label runat="server" ID="lbl_desc" Text='<%#XPath("description")%>' ></asp:Label>
<%#XPath("pubDate") %>
<br />
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</marquee>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="http://feeds.feedburner.com/breakingtravelnews/news"
XPath="rss/channel/item"></asp:XmlDataSource>
Explanation:
In XmlDataSource => DataFile => URL where you want to get the News
XPath=> rss/channed/item => these are the nodes that defined in xml file for rss after that xml has "link" "description" "title" "pubDate" that i have used in repeater to get the Data.
Happy Coding :) :)
Today I have Implemented this simple method to get the RSS feed from any other website. Usually this is used to get the Daily/Breaking/Latest News to your website.
So, Now i am going to explain how we can achieve this via simple coding.
<marquee behavious="scroll" direction="up" scrollamount="4" onmouseover="this.stop()" onmouseout="this.start()">
<div style=" text-justify: inter-word; text-align: justify">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1" >
<ItemTemplate>
<a target="_blank" href='<%# XPath("link") %>'>
<%# System.Web.HttpUtility.HtmlEncode(XPath("title").ToString())%></a>
<br />
<asp:Label runat="server" ID="lbl_desc" Text='<%#XPath("description")%>' ></asp:Label>
<%#XPath("pubDate") %>
<br />
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</marquee>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="http://feeds.feedburner.com/breakingtravelnews/news"
XPath="rss/channel/item"></asp:XmlDataSource>
Explanation:
In XmlDataSource => DataFile => URL where you want to get the News
XPath=> rss/channed/item => these are the nodes that defined in xml file for rss after that xml has "link" "description" "title" "pubDate" that i have used in repeater to get the Data.
Happy Coding :) :)
Tuesday, 2 April 2013
Tinymce Editor in Asp.net
First Download the Source Code from the TinyMce site and then
Just Add the following code in the page where you want to show your TinyMce Editor
<script src="tinymce/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode: "textareas",
theme: "advanced",
width: "600",
height: "400",
encoding: "xml",
//Call the method to Browse the image from the computer
file_browser_callback: 'fileBrowserCallBack',
plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell, \
inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste, \
directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template, \
wordcount,advlist,autosave",
setup: function(ed)
{
ed.onKeyPress.add(
function(ed, evt)
{
}
);
},
// Theme options
theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|, \
justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect, \
fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|, \
bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor, \
image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,\
charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|, \
styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom", theme_advanced_resizing: true,
// Example content CSS (should be your site CSS)
content_css: "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url: "lists/template_list.js", external_link_list_url: "lists/link_list.js",
external_image_list_url: "lists/image_list.js", media_external_list_url: "lists/media_list.js",
// Style formats
style_formats: [
{ title: 'Bold text', inline: 'b' },
{ title: 'Red text', inline: 'span', styles: { color: '#ff0000'} },
{ title: 'Red header', block: 'h1', styles: { color: '#ff0000'} },
{ title: 'Example 1', inline: 'span', classes: 'example1' },
{ title: 'Example 2', inline: 'span', classes: 'example2' },
{ title: 'Table styles' },
{ title: 'Table row 1', selector: 'tr', classes: 'tablerow1' }
],
// Replace values for the template plugin
template_replace_values:
{
username: "Some User", staffid: "991234"
}
});
// ---------This code for upload the image from your computer not from the web using url---
function fileBrowserCallBack(field_name, url, type, win)
{
//You need to create your own page to upload the image from the computer
win.open('Browse.aspx', 'Browse Image', 'width=350,height=120,left=400, top=400, toolbar= no ,status=yes,location=no,resizable=no,dependent');
win.document.forms[0].elements[field_name].value = filename;
return false;
}
//----Code End for open a new window that helps to upload the image from the client computer-----------
Then Add the following
<textarea id="Editor_textArea" name="Editor_textArea" rows="15" cols="80" runat="server"></textarea>
//In the CS file
public string bodyHtml
{
get
{
return HttpUtility.HtmlDecode(Editor_textArea.Value);
}
set
{
Editor_textArea.Value = value;
}
}
Then You can use bodyHtml where ever you want it get the data from the editor and you can store it as it is as in your editor shows
Thanx
Url ReWriting Using Url Rewriter.Net
- Open your web project in Microsoft Visual Studio .NET.
- Add a reference to the Intelligencia.UrlRewriter assembly.
- Open the web.config file in your web project.
- Add the following in the web.config file:
- <configuration>
- <configSections>
- <section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<rewriter>
<rewrite url="~/products/(.+)" to="~/products.aspx?category=$1" />
</rewriter>
</configuration> - And in the CS file or where ever you redirect to the page from put the text as in the url field like
Response.Redirect("~/products.aspx");
Thursday, 21 March 2013
Getting Value from Editor
private string StripHTML(string source)
{
string result = "";
try
{
// Remove HTML Development formatting
// Replace line breaks with space
// because browsers inserts space
result = source.Replace("\r", " ");
// Replace line breaks with space
// because browsers inserts space
result = result.Replace("\n", " ");
// Remove step-formatting
result = result.Replace("\t", string.Empty);
// Remove repeating speces becuase browsers ignore them
result = System.Text.RegularExpressions.Regex.Replace(result,
@"( )+", " ");
// Remove the header (prepare first by clearing attributes)
result = System.Text.RegularExpressions.Regex.Replace(result,
@"<( )*head([^>])*>", "<head>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(<( )*(/)( )*head( )*>)", "</head>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"(<head>).*(</head>)", string.Empty,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// remove all scripts (prepare first by clearing attributes)
result = System.Text.RegularExpressions.Regex.Replace(result,
@"<( )*script([^>])*>", "<script>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(<( )*(/)( )*script( )*>)", "</script>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(<script>).*(</script>)", string.Empty,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// remove all styles (prepare first by clearing attributes)
result = System.Text.RegularExpressions.Regex.Replace(result,
@"<( )*style([^>])*>", "<style>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(<( )*(/)( )*style( )*>)", "</style>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"(<style>).*(</style>)", string.Empty,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// insert tabs in spaces of <td> tags
result = System.Text.RegularExpressions.Regex.Replace(result,
@"<( )*td([^>])*>(<( )*br( )*(/)*>)*", " ",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(<( )*br( )*(/)*>)*( )*</td([^>])*>(<( )*br( )*(/)*>)*", "",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// insert line breaks in places of <BR> and <LI> tags
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*<( )*br( )*(/)*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*<( )*li( )*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// insert line paragraphs (double line breaks) in place
// if <P>, <DIV> and <TR> tags
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*<( |/)*div([^>])*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*<( )*tr([^>])*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*<( |/)*p([^>])*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*</table([^>])*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"(\r|\n)*</(ol|ul)([^>])*>", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// Remove remaining tags like <a>, links, images,
// comments etc - anything thats enclosed inside < >
result = System.Text.RegularExpressions.Regex.Replace(result,
@"<[^>]*>", string.Empty,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// replace special characters:
result = System.Text.RegularExpressions.Regex.Replace(result,
@" ", " ",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"•", " * ",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"‹", "<",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"›", ">",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"™", "(tm)",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"⁄", "/",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"<", "<",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@">", ">",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"©", "(c)",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@"®", "(r)",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
@" ", " ",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// Remove all others. More can be added, see
// http://hotwired.lycos.com/webmonkey/reference/special_characters/
result = System.Text.RegularExpressions.Regex.Replace(result,
@"&(.{2,6});", string.Empty,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// make line breaking consistent
result = result.Replace("\n", "\r");
// Remove extra line breaks and tabs:
// replace over 2 breaks with 2 and over 4 tabs with 4.
// Prepare first to remove any whitespaces inbetween
// the escaped characters and remove redundant tabs inbetween linebreaks
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\r)*( )+(\r)", "\r\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\r)( )+", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\t)( )+(\t)", "\t\t",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\t)( )+(\r)", "\t\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\r)( )+(\t)", "\r\t",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// Remove redundant tabs
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\r)(\t)+(\r)", "\r\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// Remove multible tabs followind a linebreak with just one tab
result = System.Text.RegularExpressions.Regex.Replace(result,
"(\r)(\t)+", "\r\t",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"[\r]+", "\r",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"[ ]+", " ",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// Thats it.
result = result.Replace("\r", "\n");
result = System.Text.RegularExpressions.Regex.Replace(result,
"[\n ]$", "",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
result = System.Text.RegularExpressions.Regex.Replace(result,
"^[\n ]", "",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
return result;
}
catch
{
return result;
}
}
Friday, 15 March 2013
How to make the HTML table in C# (on the server side, values comes from the database)
while (sqr.Read())
{
string partner_name = sqr.GetString(0);
int partner_id = sqr.GetInt32(1);
HtmlPartnerNameDiv += "<div id=" + partner_name + " class=tab_airline><a href=flights.html class=more_offers title=More Offers>More Offers" +
"</a><div class=list-head><h2>" + partner_name + " Latest Fares </h2> </div><table class=home_partnerfares><thead><tr><th width=90 scope=col>" +
"<strong>DESTINATIONS</strong></th><th width=113 scope=col ><strong>Travel dates </strong> </th><th width=70 scope=col><strong>Book by</strong></th>" +
"<th width=38 scope=col><strong> Fare </strong></th><th width=40 scope=col><strong> More </strong></th></tr></thead>";
GetAllFaresByIdGridView(partner_id);
HtmlPartnerNameDiv += HtmlTable;
}
protected string GetAllFaresByIdGridView(int id)
{
string htmlStr = "";
HtmlTable = "";
try
{
using (SqlConnection conn = DataAccess.GetConnected())
{
SqlCommand cmd = new SqlCommand("GetAllFaresByID", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.Add(new SqlParameter("@Error", SqlDbType.VarChar, 255));
cmd.Parameters["@Error"].Direction = ParameterDirection.Output;
cmd.Parameters.Add(new SqlParameter("@count", SqlDbType.VarChar, 255));
cmd.Parameters["@count"].Direction = ParameterDirection.Output;
SqlDataReader sqr = cmd.ExecuteReader();
htmlStr += "<tbody>";
while (sqr.Read())
{
string Destination = sqr.GetString(0);
string Travel_From_Date = sqr.GetString(1);
string Travel_To_Date = sqr.GetString(2);
string Book_By = sqr.GetString(3);
int Fare = sqr.GetInt32(4);
htmlStr+= "<tr ><td>" + Destination + "</td>" +
"<td>" + Travel_From_Date + " - " + Travel_To_Date + "</td><td>" + Book_By + "</td><td class=price>£" + Fare + "</td><td><a href=flights.html title=View Details>" +
"view › </a></td> </tr>";
}
}
}
catch (Exception ex)
{
//throw ex.Message;
}
htmlStr += "</tbody></table></div>";
HtmlTable += htmlStr;
return htmlStr;
}
How to format the string in the title property of the image tag(values comes from the database)
using (SqlConnection conn = DataAccess.GetConnected())
{
SqlCommand cmd = new SqlCommand("GetImageForSlider", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader sqr = cmd.ExecuteReader();
while (sqr.Read())
{
string image_path = sqr.GetString(0);
string description = sqr.GetString(1);
string action = sqr.GetString(2);
HtmlImage += string.Format("<img src=\"{0}\" title=\"<h3>{1}.</h3><span class=price>{2}</span><p><br></p><a href=http://www.giftotravels.com >This is link</a>\"/>",image_path, description, action);
}
}
{
SqlCommand cmd = new SqlCommand("GetImageForSlider", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader sqr = cmd.ExecuteReader();
while (sqr.Read())
{
string image_path = sqr.GetString(0);
string description = sqr.GetString(1);
string action = sqr.GetString(2);
HtmlImage += string.Format("<img src=\"{0}\" title=\"<h3>{1}.</h3><span class=price>{2}</span><p><br></p><a href=http://www.giftotravels.com >This is link</a>\"/>",image_path, description, action);
}
}
Monday, 11 March 2013
Insert, Edit, Delete, Update in GridView Using Asp.Net with C-Sharp And How to display images from database using image Path in GridView
aspx Code
<asp:GridView ID="Fare_Images_GridView" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"
AllowPaging="false" AllowSorting="true"
onrowcancelingedit="Fare_Images_GridView_RowCancelingEdit"
onrowediting="Fare_Images_GridView_RowEditing"
OnRowDeleting="Fare_Images_GridView_RowDeleting"
OnRowUpdating="Fare_Images_GridView_RowUpdating"
OnRowCommand="Fare_Images_GridView_RowCommand" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_image_id" runat="server" Visible="false" Text='<%# Eval("image_id") %>' ></asp:Label>
<asp:Label ID="lbl_Partner_id" runat="server" Visible="false" Text='<%# Eval("Partner_id") %>' ></asp:Label>
<asp:Label ID="lbl_image_name" runat="server" Visible="false" Text='<%# Eval("image_name") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Logo">
<ItemTemplate >
<asp:Image ID="lbl_image_path" runat="server" ImageUrl='<%#Eval("image_path") %>' Width="70px" Height="70px" />
</ItemTemplate>
<EditItemTemplate>
<asp:Image ID="lbl_image_path" runat="server" ImageUrl='<%#Eval("image_path") %>' Width="40px" Height="40px" />
<asp:FileUpload ID="FileUploadImagePartner" FileName='<%#Eval("image_path") %>' Width="100px" runat="server" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:FileUpload ID="FileUploadImagePartner" FileName='<%#Eval("image_path") %>' Width="100px" runat="server" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Partner Name">
<ItemTemplate>
<asp:LinkButton ID="link_Partner_Name" CommandName="Partner_Name" CommandArgument='<%# Eval("Partner_id") %>' runat="server" Text='<%#Eval("Partner_Name") %>' ></asp:LinkButton>
<%-- <asp:Label ID="lbl_Partner_Name" runat="server" Visible="true" Text='<%# Eval("Partner_Name") %>' ></asp:Label>--%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_Partner_Name" runat="server" Text='<%#Eval("Partner_Name") %>' Width="80px" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server"
CommandName="Edit" Text="Edit" ></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btndelete" runat="server"
CommandName="Delete" Text="Delete" OnClientClick="return confirm('This will delete your all Fares.Are you sure you want to delete? ');" ></asp:LinkButton>
<asp:LinkButton ID="btnupdate" runat="server"
CommandName="Update" Text="Update" ></asp:LinkButton>
<asp:LinkButton ID="btncancel" runat="server"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="white" /><%--#2461BF--%>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
CS Code
//Method in the Data Access Layer
public void FillGridView(string strProName, System.Web.UI.WebControls.GridView GridViewName)
{
//int status = 0;
DataTable dt = new DataTable();
try
{
using (SqlConnection conn = DataAccess.GetConnected())
{
SqlCommand cmd = new SqlCommand(strProName, conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sqlda = new SqlDataAdapter();
sqlda.SelectCommand = cmd;
sqlda.Fill(dt);
GridViewName.DataSource = dt;
GridViewName.DataBind();
}
}
catch (Exception ex)
{
//throw ex.Message;
}
}
//Call on Presentation Layer
protected void GetAllImagesPartner()
{
da.FillGridView("ShowPartnerImagesGridView", Fare_Images_GridView);
}
protected void Fare_Images_GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
Fare_Images_GridView.EditIndex = -1;
GetAllImagesPartner();
}
protected void Fare_Images_GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
Fare_Images_GridView.EditIndex = e.NewEditIndex;
GetAllImagesPartner();
}
protected void Fare_Images_GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string filename = "";
string image="";
try
{
FileUpload fileupload = (FileUpload)Fare_Images_GridView.Rows[e.RowIndex].FindControl("FileUploadImagePartner");
if (fileupload.HasFile)
{
// string filename = Path.GetFileName(this.fileupload.PostedFile.FileName);
filename = fileupload.FileName;
image=filename;
fileupload.SaveAs(Server.MapPath("~/Partner_Fare_Images/" + filename));
}
else
{
Label image_name = (Label)Fare_Images_GridView.Rows[e.RowIndex].FindControl("lbl_image_name");
image=image_name.Text;
//filename = image_name.ToString();
}
Label lbl_Partner_Id = (Label)Fare_Images_GridView.Rows[e.RowIndex].FindControl("lbl_Partner_id");
Label lbl_image_Id = (Label)Fare_Images_GridView.Rows[e.RowIndex].FindControl("lbl_image_id");
TextBox txt_Partner_Name = (TextBox)Fare_Images_GridView.Rows[e.RowIndex].FindControl("txt_Partner_Name");
using (SqlConnection con = DataAccess.GetConnected())
{
SqlCommand cmd = new SqlCommand("UpdatePartnerImage", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Partner_Id", lbl_Partner_Id.Text);
cmd.Parameters.AddWithValue("@Image_Id", lbl_image_Id.Text);
cmd.Parameters.AddWithValue("@Image_Path", "Partner_Fare_Images/" + image);
//cmd.Parameters.AddWithValue("@Image_Path", );
cmd.Parameters.AddWithValue("@Partner_Name", txt_Partner_Name.Text);
cmd.Parameters.AddWithValue("@image_name", image);
cmd.ExecuteNonQuery();
Fare_Images_GridView.EditIndex = -1;
GetAllImagesPartner();
}
}
catch (Exception ex)
{
}
}
protected void Fare_Images_GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
GridViewRow row = Fare_Images_GridView.Rows[e.RowIndex];
Label Image_Id = (Label)row.FindControl("lbl_Image_id");
Label Partner_Id = (Label)row.FindControl("lbl_Partner_id");
using (SqlConnection con = DataAccess.GetConnected())
{
SqlCommand cmd = new SqlCommand("deletePartnerFullData", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Image_Id", Image_Id.Text);
cmd.Parameters.AddWithValue("@Partner_Id", Partner_Id.Text);
cmd.ExecuteNonQuery();
con.Close();
GetAllImagesPartner();
}
}
catch (Exception ex)
{
}
}
protected void Fare_Images_GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Partner_Name")
{
using (SqlConnection con = DataAccess.GetConnected())
{
try
{
int rowindex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
LinkButton Partner_Name = (LinkButton)row.FindControl("link_Partner_Name");
//Label Partner_Id = (Label)row.FindControl("lbl_Partner_Id");
hdn_Add_Fare_Partner.Value = Partner_Name.Text;
hdn_Add_Fare_Id.Value = rowindex.ToString();
lbl_Add_Fare.Text = "";
lbl_Add_Fare.Text = "Add Fare For " + hdn_Add_Fare_Partner.Value;
GetAllFaresById(Convert.ToInt32(hdn_Add_Fare_Id.Value));
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
con.Close();
}
}
}
}