|
Ya, I got your problem. Actually, if you dont place runat=server for a control inside Repeater, it will evaluate data correctly. For a control having runat="server" you need to do this from your codeBehind.
The ItemDataBound event is the best candidate for you.
Add asp:Repeater OnItemDataBound="RepeaterItemEventHandler" in the control
public void RepeaterItemEventHandler(object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternateItem)
{
Label lbl = e.Item.FindControl("lblitem") as Label;
lbl.Text = DataBinder.Eval(e.Item.DataItem, "fao_subcategory");
}
}
also to remind you, you can set the javascript there, but it will not execute when text property gets loaded. Rather put a RegisterStartupScript which will modify the data.
this.ClientScript.RegisterStartupScript(this.GetType, lbl.ClientId, "GetCatDesc('" + lbl.ClientId + "');" , true);<br />
like this.
Just modify this according to what you need. Do this inside the RepeaterItemEventHandler
|
|
|
|
|
thanks abishek,
i agree and i will work and revert you as per the method you said,
but my question is you said putting runat="server" i.e server side control cannot be used directly inside the repeater, look below
<tr><td align="left" >javascript:GetCatDesc(<%#Eval("fao_ddlcategory")%>)</td></tr>
<tr><td align="left"><%#Eval("fao_description")%></td></tr>
here the description is printing correctly and why not my funcion??
i have doubt on this can you clear me please if u dont mind,
and am sorry if i disturb you.
and
lbl.Text = DataBinder.Eval(e.Item.DataItem, "fao_subcategory");
in this line am getting
Error 26 Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
thanks in advamce
modified on Thursday, December 31, 2009 2:16 PM
|
|
|
|
|
Hema Bairavan wrote: you said putting runat="server" i.e server side control cannot be used directly inside the repeater
what... No no. You can put runat="server" control inside ItemTemplate of a Repeater and only those controls that you state runat="server" could be found during ItemDataBound Event.
I said you cant specify server tags in the designer when you place runat="server"
<asp:Label runat="server" Text="<%# Eval("fao_ddlcategory")%>" is not possible
rather
you use
<span><%# Eval("fao_ddlcategory")%>" </span> which is client side control, or rather you directly place in the TD block.
Hema Bairavan wrote: here the description is printing correctly and why not my funcion??
Ya.. It will print. Actually writing javascript:func in the html is meaningless. javascript protocol is used to define that the line prior to it is a javascript one. If you want to place/run a script, place it below all controls in a script block like
<script type="text/javascript">
GetCatDesc(val);
</script>
If you place your javascript in RegisterStarupScript it will appear at the bottom of the page and thus find all the control in it.
Hema Bairavan wrote: in this line am getting
Error 26 Cannot implicitly convert type 'object' to 'string'.
Yes of course, you must do
lbl.Text = DataBinder.Eval(e.Item.DataItem, "fao_subcategory") as string;
Hope you get the issues right..
Happy New Year from me.
|
|
|
|
|
I don't know until the page is created how many radiobuttonlists I will need. So, I create them and store the number in a hidden label. But, when I want to get the selection from the radiobuttonlist on postback, I keep getting a object reference error. I've tried finding the control without a findControl, with a findControl and with a master page content reference and findControl. No luck. Any help appreciated...
Dim myConStr As String = ""
If lblSidCount.Text <> "0" Then
Dim x As Integer = 1, y As Integer = Convert.ToInt32(lblSidCount.Text)
Do While x <= y
Dim myContent As ContentPlaceHolder = CType(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
Dim radConStr As New RadioButtonList
radConStr = CType(myContent.FindControl("rad" & x.ToString), RadioButtonList)
myConStr &= radConStr.SelectedItem.Text & "~"
x = x + 1
Loop
myConStr = Left(myConStr, Len(myConStr) - 1)
End If
|
|
|
|
|
This seems to work - am I crazy for doing this?
Private radCon As RadioButtonList()<br />
Protected Overrides Sub OnInit(ByVal e As EventArgs)<br />
MyBase.OnInit(e)<br />
If (Request("str") = 1) Then<br />
Dim myList As dsSql = New dsSql() ''''instantiate the function to get dataset<br />
Dim ds As New Data.DataSet<br />
ds = myList.dsConSessionTimes(Request("eid"))<br />
If ds.Tables("conSessionTimes").Rows.Count > 0 Then<br />
radCon = New RadioButtonList(ds.Tables("conSessionTimes").Rows.Count - 1) {}<br />
Dim i As Integer = 0<br />
Dim rad As RadioButtonList = New RadioButtonList()<br />
rad.ID = "rad" + i.ToString()<br />
rad.DataSource = ds.Tables("conSessions")<br />
rad.DataTextField = ds.Tables("conSessions").Columns("session_name").ToString<br />
rad.DataBind()<br />
rad.SelectedIndex = 0<br />
phConcurrent.Controls.Add(rad)<br />
radCon(i) = rad<br />
For Each j As Data.DataRow In ds.Tables("conSessionTimes").Rows<br />
Dim rad As RadioButtonList = New RadioButtonList()<br />
rad.ID = "rad" + i.ToString()<br />
rad.DataSource = ds.Tables("conSessions")<br />
rad.DataTextField = ds.Tables("conSessions").Columns("session_name").ToString<br />
rad.DataBind()<br />
rad.SelectedIndex = 0<br />
phConcurrent.Controls.Add(rad)<br />
radCon(i) = rad<br />
i = i + 1<br />
Next<br />
End If<br />
End If<br />
End Sub
|
|
|
|
|
Hi, I am trying to build a website that provides stock information like the one in Yahoo Finance:
http://finance.yahoo.com/echarts?s=MSFT#chart7:symbol=msft;range=3m;indicator=bollinger+volume;charttype=line;crosshair=on;ohlcvalues=0;logscale=on;source=undefined
All the source and analytical data is already there, however I am trying to implement a mechanism that allows users to click and graph additional chart on each mouse click, meaning there'll be multiple postbacks. The problem is with each postback, existing charts plotted by users should remain on the page, and only the new chart is added.
In the link above, if you click on "TECHNICAL INDICATORS", a dropdown list appears allowing users to add additional chart to the page, without destroying existing charts that's currently on the page. This is exactly the kind of function I want to have for my website.
So how could I implement this mechanism using ASP.NET? I am thinking this is a Viewstate issue. Should my goal be maintaining the viewstate of the chart itself? Or should I perhaps store user-defined inputs temporarily into a control (perhaps a label control)and maintain the viewstate of that, based on which the chart will be plotted?
Or is there a more elegant approach to this?
I'd greatly appreciate any suggestions! Thank you.
|
|
|
|
|
Could someone please give me some suggestions if possible? Thanks!
|
|
|
|
|
Try using ajax and avoid postback.
Asp.Net Ajax provides you a number of ways to stay on the page and add
contents to the same page from the server.
Hope this will help.
|
|
|
|
|
Thanks for the reply Anurag. I thought with AJAX, there'll still be postbacks, just partial postback in the AJAX panel? Thus if I put my chart in the panel, it'll still post back and redraw the chart every time I click the "ADD New Chart" button right?
Thanks!
|
|
|
|
|
Hi,
Ajax doesn't always mean UpdatePanel.
When user clicks add new chart, Create a new XmlHttpRequet,
Send the request for the new chart to the server,
Get the new chart as a response from the server,
Then, add it to your page using javascript.
Postback is not needed in this case.
You may need to go through tutorials or book if facing problem.
|
|
|
|
|
Hi All,
Hope everyone had a Merry Xmas and Happy New Year.
Just a question...I have made an RSS Feed which is syndicated by the Mozilla and IE , as an output of an XML file. However when either of the feeds show, they show the pubDate as being totally different dates to what is shown in the XML file. Even when I look at the source, the XML file still shows the correct dates as opposed to what is shown in the browser.
What do you guys think is the problem? Heres my code. Cheers.
public static void CreateNewsFeed(string mappath)
{
FileStream fs = null;
StreamWriter sw = null;
try
{
using (SqlConnection conn = Connection.connect())
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "ShowNewsFeed";
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = cmd.ExecuteReader();
fs = new FileStream(mappath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
sw = new StreamWriter(fs);
sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//ISO-8859-1
//xmlns:atom=\"http://www.w3.org/2005/Atom\"
sw.WriteLine("<rss version=\"2.0\">");
sw.WriteLine("<channel>");
sw.WriteLine("<title>Company Name</title>");
sw.WriteLine("<link>http://www.companyname.com.au/Home/News/News.aspx</link>");
sw.WriteLine("<description>News and the latest updates</description>");
sw.WriteLine("<language>en-us</language>");
while (reader.Read())
{
DateTime dt = (DateTime)reader["datePosted"];
sw.WriteLine("<item>");
sw.WriteLine("<title>" + reader["title"].ToString() + "</title>");
sw.WriteLine("<link>http://www.companyname.com.au/NewsArticle.aspx?newsID=" + reader["newsID"] + "</link>");
sw.WriteLine("<description>" + reader["description"].ToString() + "</description>");
sw.WriteLine("<pubDate>" + dt.ToString("R") + "</pubDate>");
sw.WriteLine("</item>");
}
sw.WriteLine("</channel>");
sw.WriteLine("</rss>");
sw.Close();
fs.Close();
}
}
catch (Exception m)
{
throw new Exception(m.Message);
}
}
|
|
|
|
|
HELLO All
Recently i found this article about reporting with word document ,when i used the sample code it's working fine ,but rather plain , what if i want spice my report , i have an already designed word reports ,they are simple forms , when i saved them as XML i got this lengthy xml file ,now of course i have some blank cells , in the reports that i want to fill since the report is basically a table , here comes the headache ,HOW TO GET TO THE PARTICULAR NODE? i have solved this problem in a hard way i wonder if there is a better way DOES ANY1 KNOW AN EASIER WAY TO GET TO THE NODES AND OVERWRITE THEM? ANY GOOD ARTICLE ABOUT THIS TOPIC
THANX IN ADVANCE
by the way here is the hard solution of mine ,i first read copy xml file into .txt file then read it and indexof() the cell to know where is it exactly i want to insert my data the code would like like this
fp = File.OpenText("C:\Documents and Settings\Administrator.RFF-SRV0\Desktop\" & "NoteVactionXML.txt")
_ManipulationStr = fp.ReadToEnd()
Dim str, resl As String
resl = _ManipulationStr
Dim index As Integer = 0
str = "<w:r w:rsidrpr="" 00ea5324""="">" _
& "<w:rpr>" _
& "<w:rfonts w:cs="" simplified="" arabic""="">" _
& "<w:b>" _
& "<w:bcs>" _
& "" _
& "<w:t>" & "خن" & "" _
& ""
resl = resl.Insert(548 + 10566, str)
fp.Close()
strHTMLContent.Append(resl)
HttpContext.Current.Response.Write(strHTMLContent)
HttpContext.Current.Response.End()
HttpContext.Current.Response.Flush()
Do i have to do the above for each item?
I HOPE NOT
|
|
|
|
|
you are a very bold person
I am assuming you have an xml-document :
.Net has some classes you want : XmlReader and XmlDocument .
A search for those terms should give you plenty articles to read.
|
|
|
|
|
how creat word document in asp.net use by vb.net
|
|
|
|
|
Hi ,
Is there any Javascript/Jquery slider control for selecting a range of dates ?.Could you please let me know ?
With Warm regards..
|
|
|
|
|
|
I have a button and a repeater, its datasource is a list of strings. When I click on the button, a new item is added to the repeater's datasource and the page refreshes, but I can't see the change in the repeater till I refresh the page again. What should I do in order to see the changes immediatly?
|
|
|
|
|
Make sure you are rebinding the repeater control during postback. If you are doing this please show us the code.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
i want to allow the user to enter apostrophe in the name entered in the text box.. it cant be given as e.KeyChar == '''. can somebody help me i am new to this..
|
|
|
|
|
Currently, how are you validating your textbox?
|
|
|
|
|
i have just started when i was writing the code it showed me this error
|
|
|
|
|
\' maybe.
Why not use regular expression and do the validation in javascript?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
steps for how to pass parameters to crystal reports throug textbox or dropdownlist using asp.net with c#.net
in design time text box is not available in tool box how to take textbox or dropdownlist
|
|
|
|
|
Did you tried the solution given in your last post?
Are you facing any problem with that?
Search google, you'll find many examples of parameter passing to crystal reports.
|
|
|
|
|
in the tool box there is no textbox, dropdownlist controls then how to take values from these controls
|
|
|
|