Wednesday, July 8, 2009

Validate radio button in datagrid, datalist, gridview on button

Here  'questionlist' is the id of Datalist or datagrid or Gridview or repeater

u call this function on button events

<button onclick="return isconfirm()" />

<script language=javascript>
function isconfirm()
{

var counter=0;

var obj=document.getElementById("<%=questionlist.ClientID%>").getElementsByTagName("input");
for(i=0;i<=obj.length-1;i++)
{
if(obj[i].type=="radio" && obj[i].checked==true)
{
counter++;
}
}
if(counter==0)
{ alert('Plz Select question Answer');
return false
}
return true;
}

</script>

Wednesday, May 27, 2009

Get Rss data using javascript

Place bellow script in header part

for javascript file go to http://jquery.com

<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript" language=javascript>
$(document).ready(function() {

$.ajax({
type: "GET",
url: "http://yourdomain.com/rss.xml",
dataType: "xml",
success: function(xml) {
$('#update-target').empty();
var str="";

$(xml).find('item').each(function(){

var title = $(this).find('title').text()
var link = $(this).find('link').text()
var desc = $(this).find('description').text()
str +="<tr><td><a href='"+link+"' >"+title+"</a><br />";
str+="<a href='"+link+"' >"+desc.substring(0,100)+"...</a></td></tr>";

}); //close each(
$('#update-target').html(str);
}
}); //close $.ajax(
$("#msg").ajaxError(function(event, request, settings){
$(this).append("Error requesting page " + settings.url + "");
});

}); //close $(
</script>

[/sourcecode]

Place bellow html part in body tab

[sourcecode language="html"]

<Table id='update-target'>

</Table>
<div id=msg></div>

Tuesday, March 24, 2009

job scheduling which work at time interval in web application in asp.net

I am created that type of schedule which work properly. if that is helpfull for u then u appreciate it.

using System.Threading;

as namespace

following add in global.asax.cs

protected static Timer _timer;

protected void Application_Start(object sender, EventArgs e)
{
if (_timer == null)
{
var timerCallback = new TimerCallback(JobModulecls.jobshedule);//jobschedule is method which define in JobModulecls class as static method
var startTime = 0;
var interval = 60000; // 60 seconds
_timer = new Timer(timerCallback, null, startTime, interval);
}

}

protected void Application_End(object sender, EventArgs e)
{
_timer = null;
}

public sealed class JobModulecls
{
public static void jobshedule(object state)
{
//here u can write job shcheduling work such as
// coonect to database and work on table on time day schedule

}
}

Saturday, January 3, 2009

Color char in any string

string name = "hello vinod how r u";

Random rd=new Random();

CharEnumerator ct = name.GetEnumerator();
while (ct.MoveNext())
{

int r = rd.Next(0, 255);
int g = rd.Next(0, 255);
int b = rd.Next(0, 255);
string rgb = r.ToString() + "," + g.ToString() + "," + b.ToString();
Response.Write("<span style='color:rgb(" + rgb + ");font-weight:bold;font-family:Verdana;font-size:15px'>" + ct.Current + "</span><br />");
}

nesting repeater in datalist (slider menu)

put in head tag

<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script language=javascript>
function show(id)
{
var tc=document.getElementById("tot").value;
for(var i=1;i<=tc;i++)
{
if("div"+i==id)
{

$("#div"+i).show("slow");
}
else
$("#div"+i).hide("slow");
}
}
// window.onload=show('div1')
</script

in body tag
<div>
<asp:HiddenField ID="tot" runat=server />
<asp:DataList ID="dl_cat" runat=server >
<ItemTemplate>
<div style="color:white;font-size:13px;font-weight:bold;cursor:pointer;width:250px;height:20px;background-color:Gray;padding-bottom:3px;padding-top:3px;padding-left:5px" onclick="show('div<%#Container.ItemIndex+1%>')" >
<%#Eval("categoryname") %>
</div>
<div id='div<%#Container.ItemIndex+1%>' style="background-color:Yellow;display:none">
<asp:Repeater ID="rp_subcat" DataSource='<%#DataBinder.Eval(Container, "DataItem.InnerVal") %>' runat=server >
<ItemTemplate>
<span style="padding-left:10px"><%#Eval("productname") %></span><br />
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:DataList>
</div>
protected void Page_Load(object sender, EventArgs e)
{

DataAccessLayer dl = new DataAccessLayer();
DataSet ds = new DataSet();
dl.RunProcedure("cate_product", ref ds);
ds.Relations.Add("InnerVal", ds.Tables[0].Columns["categoryid"], ds.Tables[1].Columns["categoryid"]);
tot.Value = ds.Tables[0].Rows.Count.ToString();
dl_cat.DataSource = ds.Tables[0];
dl_cat.DataBind();

}
CREATE PROCEDURE [dbo].[cate_product]

AS

select c.categoryid,c.categoryname,p.productid,p.productname into #tamp  from categories c

inner join products p on c.categoryid=p.categoryid

select distinct categoryid,categoryname from #tamp

select categoryid,productname from #tamp

drop table #tamp
GO
AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath