|
Hi,
My site is based on ASP.NET (C#) with sql server as the data source.
My Task:
Create a table based on the data source and when data is changed on the data source (sql server) update
the client table, but only update the cell with the data the was changed and not all the table – no page refresh.
Let’s say that checking for updates happens every 10 seconds.
There should be no data manipulation by the client such as insert/update/delete.
It’s something like a stock ticker that only updates data when it’s needed and only the data the was changed.
There’re lots of technologies out there: Ajax, Comet, jQuery, Linq etc.. and I’m getting lost with a task that shouldn’t be so complicated.
Comet requires a constant connection between the client & server and can be trouble when working with lots of clients.
What the right way to go?
Can you point me to a sample of such grid?
Thanks,
Assaf.
|
|
|
|
|
Given these requirements you will need to use Ajax to make an out of band call to retrieve the database info. From there JQuery will help, though it isn't necessary, with updating the DOM if necessary. That's it. There are plenty of examples on Using AJAX.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
can you please point me to an example that do this?
Thanks,
Assaf
|
|
|
|
|
How about here[^]?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
google id full of examples but most of them are much more complicated in terms of user/client events and lack the part of DB changes that are being fetched by the client.
i'll appreciate an example.
Thanks,
Assaf.
|
|
|
|
|
Google is not going to provide you with a ready made solutions, neither are we. You have to learn to think for yourself.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
stassaf wrote: and I’m getting lost with a task that shouldn’t be so complicated.
Before you start to learn how
to do the updates you need something
to update.Have you already done something
similar to this ?
1. Create aspx page
2. Add to it a GridView
3. Fill a dataset from sql query
4. Set the GridView data source to the
dataset and bind
After this you can add methods to
stassaf wrote: when data is changed on the data source (sql server) update
the client table, but only update the cell with the data the was changed and not all the table
You can use updatepanel or XmlHttpRequest Object
or even an iframe to get the new data from server
without a page refresh.
Once you have this data you can then compare it to
existing data to find changes then update only the
cells whose data has changed.
Do you have any working code now ? If not follow the
steps i have laid out asking for help as needed.
|
|
|
|
|
Use an ajax update panel (UpdatePanel1) triggering a Timer Tick (Timer1) function which contains the UpdatePanel1.Update(); and that's all
|
|
|
|
|
thanks for your reply.
i'm not new to asp.net. but it's my 1st steps in asp.net ajax.
updatepanel looks to me as the answer to my task, can you point me to an example?
Thanks,
Assaf.
|
|
|
|
|
i'm not new to asp.net. but it's my 1st steps in asp.net ajax.
i'll appreciate an example that use the updatepanel which looks to me as the answer to my task.
Thanks,
Assaf.
|
|
|
|
|
|
If you're using Visual Studio 2008 or Visual Web Developer 2008, you can see the tools for Ajax Extensions or if is 2005, look here[^]
then add the timer and an update panel like...
<asp:Timer ID="Tmr_Update" runat="server" ontick="Tmr_Update_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdPnl_UpdateEvery_5Sec" runat="server" UpdateMode="Conditional">
< ContentTemplate>
your content here
< /ContentTemplate>
< Triggers>
<asp:AsyncPostBackTrigger ControlID="Tmr_Update" EventName="Tick" />
< /Triggers>
< /asp:UpdatePanel>
You add a trigger and that means that the content template of the update panel will update every Tick event for the Tmr_Update Control...
you can Add the interval of the update like
Tmr_Update.Interval = 5;
Ahh don't forget the scriptManager before the tag
<asp:ScriptManager ID="SM_Detail" runat="server">
< /asp:ScriptManager>
Good luck
|
|
|
|
|
Thanks PunkIsNotDead,
your replt is very helpfull and it's the base for what i'm doing.
insted of "your content here" i'm using a datagrid that updates.
but the tricky part is that i want to be able to update only the certain cell data that was changed and not the whole grid.
also there could be n grids on my page and i can't know on advance how mant grid should be, also during running more grids can be added.
currently every "Tmr_Update_Tick" i'm doing a merge between the current datatable and the new one that i'm getting from the DB.
how can i do cell update, maybe even highlight it when there's a change?
also use n grids when n is known before runung?
my code right now shows one grid with the current data and one grid with only the changes:
.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Tmr_Update" runat="server" ontick="Tmr_Update_Tick"/>
<asp:UpdatePanel ID="UpdPnl_UpdateEvery_5Sec" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="Server"></asp:GridView>
<br /><br /><br />
<asp:GridView ID="GridView2" runat="Server"></asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Tmr_Update" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
.cs
protected string connStr = "xxxx";
protected DataTable dTable = new DataTable();
protected DataTable dTable1 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
//On Load
Tmr_Update.Interval = 100000;//seconds
if (!IsPostBack)
{
GetDT(ref dTable);
BindGridView(ref dTable);
}
}
private void GetDT(ref DataTable myDT)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand objComm = new SqlCommand();
objComm.Connection = conn;
objComm.CommandType = CommandType.StoredProcedure;
objComm.CommandText = "someSP";
SqlDataAdapter dAd = new SqlDataAdapter(objComm);
dAd.Fill(myDT);
conn.Close();
}
private void BindGridView(ref DataTable myDT)
{
GridView1.DataSource = myDT;
GridView1.DataBind();
}
protected void Tmr_Update_Tick(object sender, EventArgs e)
{
//
GetDT(ref dTable1);
//dTable.Merge(dTable1);
DataTable d3 = new DataTable();// = dTable1.GetChanges();
d3.Merge(dTable);
d3.AcceptChanges();
d3.Merge(dTable1);
GridView1.DataSource = dTable1;
GridView1.DataBind();
GridView2.DataSource = d3.GetChanges();
GridView2.DataBind();
dTable = dTable1;
}
Thanks,
Assaf.
|
|
|
|
|
Hi! you could use jQuery highlight effect Here[^]. Is the first thing I think you can use in to Highlight a cell.
And try using a updatepanel in a
<asp:templatefield headertext="Prueba">
<itemtemplate><asp:updatepanel runat="server" id="UpdPnl_Test" updatemode="Conditional">
< ContentTemplate>
< div class="DivTest">< %#Eval("DataToUpdate")%>< /div>
< / ContentTemplate>
< Triggers>
< asp:AsyncPostBackTrigger ControlID="Tmr_Update" EventName="Tick" / >
< / Triggers>
< / asp:UpdatePanel>
< / ItemTemplate>
< / asp:TemplateField>
and on the timer.tick event you must compare the last data and the new. and performing the jQuery event in which divs satisfy the condition of "diferent than last time" or something like that.
That would be hard men...
would be like < div... ...showHL='< %#Eval("UpdateThis")%>'> ...
and in the DataTable add a column with 'UpdateThis' to change (from false to true for example) in case that the last data changed too. And in script side you must select all divs that have changed every post back (or timer.tick)
$(document).ready(function(){
$('div[showHL="true"]')effect(
$("#effect").effect(selectedEffect,options,500,callback););
//callback function to bring a hidden div back
function callback(){
setTimeout(function(){ $('div[showHL="true"]').removeAttr('style').hide().fadeIn();
}, 1000);
});
note: jQuery function is not tested and i'm not sure of if it's sintax is ok too.
modified on Wednesday, May 5, 2010 12:38 AM
|
|
|
|
|
hello everyone,
I'm working on n-tier application and I want to use html controls, for example, instead of dropdownlist I'll use the select and instead of gridview I'll use a html table,
the problem that I could not fill them using sql query, and all the result of research on google there are php, if someone can help me in this level, thank you
|
|
|
|
|
Well, all ASP.NET controls render as html controls so I don't see what the issue is.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
membre123 wrote: instead of dropdownlist I'll use the select
This should be fine and there must not be an issue filling either one. Both expose similar properties to fill the values.
membre123 wrote: instead of gridview I'll use a html table,
This is tough! Though Gridview is rendered as table but the way values are defined for both, pagination, sorting, etc will be missing in Table... It cab be done with effort!...
What is the reason you are trying to convert them so? Ultimately ASP.NET controls are rendered as HTML only!
Further, what exact issue you are facing while filling them using SQL query - i dont find any reason you shouldn't be able to!
|
|
|
|
|
Hi! use in select and table like this...
<select id="yourAspSelectID" runat="server"></select>
<table id="yourAspTableID" runat="server"><tr><td>Content</td></tr></table>
And then you could reference it's id in code behind!
good luck
|
|
|
|
|
ok, thank you, so I'll link id for each control so my c code, for example if I want to fill a select controle by a "select client from id_clt" I'll do it:
in DAL:public SqlDataReader selection (string agrecvt)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "selectioncvt";
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataReader dr=cmd.ExecuteReader())
{
while (dr.Read())
{
agrecvt = Convert.ToString(dr["@agremcvt"]);
}
return dr ;
}
}
in BLL: public SqlDataReader selection(string agrecvt)
{
try
{
return cvtdal.selection (agrecvt );
}
catch
{
throw;
}
finally
{
cvtdal = null;
}
}
and in code interface:
protected void Page_Load(object sender, EventArgs e)
{
busniss_object.Classe_cvt cvt = new busniss_object.Classe_cvt();
Select4.DataSource = cvt.selection();
}
but it does'nt work if you can correct my code, thank you
|
|
|
|
|
I fill it with a DataTable like this...
DataTable Dt = new DataTable("Dt_Source");
Dt.Columns.Add("Id", System.Type.GetType("System.Int32"));
Dt.Columns.Add("Name", System.Type.GetType("System.String"));
Dt.Rows.Add(1, "Text1");
Dt.Rows.Add(2, "Text2");
Dt.Rows.Add(3, "Text3");
Dt.Rows.Add(4, "Text4");
Select1.DataSource = Dt;
Select1.DataTextField = "Name";
Select1.DataValueField = "Id";
Select1.DataBind();
good luck!
|
|
|
|
|
Dear all,
Im new in this and hope to get some advice.
I want to build a webservice that has to get some data as parameter from the client application. the data from the client side are records from there database.
my websercie has to send then these data to a soap server through 'HttpWebRequest'.
Can i get the data as Datatable? and then send as stream to the soap server?
Or maybe there is a better easier ways? your suggestion please
Thanks in advance.
|
|
|
|
|
A datatable is going to add a lot of overhead. I would suggest creating a class that represents the stuff you have in a row. That would then be a parameter of your web service. Those are known as "complex types" in the web services world. How you send it on after that depends on what is on the receiving end. Just saying it is SOAP doesn't give enough detail to say what kind of format it would accept. Are you doing anything with the data on the web server before you send it on? It seems like you are adding a middle man for no reason.
|
|
|
|
|
Hi T M Gray,
Thank you for reply!
By creating a class that represents the stuff in a row, the client app has to send then each record separately, so they have to call the webservice once for each record. Don't we have this way more overhead then sending the entire datatable at once?
And yes the webservice is acting as middle man between internet and the soap server for security reasons. the webservice has to send the data as string to that soap server.
|
|
|
|
|
Hi, all,
I have a gridview table with some columns vertical orientated, but after export to excel, all the column headers are horizontal, how can I keep the same format as gridview?
Also set the header row height after exported to excel?
Thanks!
|
|
|
|
|
Hi, all,
I have a gridview with sorting header, after I export it to excel, the links are still there, how can I remove the sort link?
I search the internet, somebody suggest using the following codes in Export_Click method:
GridView1.AllowSorting = false;
GridView1.DataBind();
But after I use this, the generated excel file have no data at all, only some html codes line .... .
Can anybody help me? Thanks!
|
|
|
|