|
I am trying to display images in a datagrid. I can place the image control into the datagrid ok, but when it comes to retrieving the imageurl from my sqlexpress database it doesn't load the image. Can anyone help please? Below is some of the code i have already.
<asp:DataGrid ID="dg_candidates" runat="server" AutoGenerateColumns="False" Width="600px" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateColumn>
<ItemTemplate> <asp:Imageid="img_candidate"runat="server"AlternateText="Candidate" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.image") %>'></asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="lbl_candidate" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.candidate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="lbl_votes" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.votes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<mbrsc:RowSelectorColumn></mbrsc:RowSelectorColumn>
</Columns>
</asp:DataGrid><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Conn %>"
SelectCommand="SELECT [Candidate], [Image], [Votes] FROM [Candidates]"></asp:SqlDataSource>
|
|
|
|
|
Hi,
What exactly r u storing in the database as a path of the image.
Do u store only the name of the image or path of the image?
Is that path relative or fixed?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hi,
I am stroing the path of the file as follows:
C:\Documents and Settings\mdf3mgp\My Documents\Visual Studio 2005\WebSites\Voting_System\Images\top.jpg
|
|
|
|
|
Better view the Page Source and see if the path is valid.
Regards,
Arun Kumar.A
|
|
|
|
|
Hi,
Your images reside on client machine or on server ?
If they are on server then you should store relative paths of them in the database and then assign those paths to to the imagecontrols.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Hai to all,
How to get refresh the data after inserting data into database in the form,if i click on refresh button ,there is nothing happening.CAn any one suggest me with some code ,so that i can refresh after editing something on the form and database changes should be shown on the form itself.
Here i am using Navigation Buttons,after adding somvalues,i f i go for the just inserted value,it is not showing,it is giving an error like no data present.
I haven't given any code seperately for refresh.
kissy
|
|
|
|
|
It sounds like you need to rebind the grid after clicking the button to insert.
|
|
|
|
|
hai,
thanks for ur reply,Here i am not using any type of Grid,Just a simple form having txt's and ddl's and label's.
Can u please suggest me some idea.How can i refresh the data which is already sent to database.THe refresh shd shown while i am navigating the buttons.The last entered record is not appearing at that perticular parse.If i close the form and if i again open,then it is coming.
I want after immediate insertion the data shd be refresh
Regards
kissy
|
|
|
|
|
hi.
Post some code. Let's see what you are doing.
Are you doing the data retrieval again after the insert?
|
|
|
|
|
I display some boolean values in checkboxes. Is it possible instead of the checkboxes the values to displayed as On if the database cell=True or Off if the value=False.
Also if all the values in a column are the same e.g kjaslklkajl. Is it possible to represent this colunm with different value? kjaslklkajl=Some Name.
Thanks
|
|
|
|
|
How come you are displaying values in the checkboxes? U'r question is not clear ...
Koushik
|
|
|
|
|
HI,
Make autogeneratecolumns property of gridview to false.
and create <asp:BoundField> for each of the column you need to display.
This way your boolean column will display "True" and "False" in the gridview.
Now you can change this to "On" and "Off" by writing code in the "RowDataBound" event of the gridview.
protected void gvDemo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[2].Text == "True")
{
e.Row.Cells[2].Text = "On";
}
else
{
e.Row.Cells[2].Text = "Off";
}
}
}
set OnRowDataBound = "gvDemo_RowDataBound" in the gridview.
The code for your sencond problem can also be written here only cellindex will be changed.
I hope this will help you.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
I use VB.net but this code is exactly what I need.
Thank you guys.
|
|
|
|
|
Hello ALL!
I have a problem and I didnt find an aswer into articles.
I have a datalist, a sqldatasource and a page.
I should select some data from database and display it on the page using datalist.
I can do it.
But i should add a footer for navigation into my datalist beacause when page loaded datalist has ALL rows from query but it must be dispalying only for 20 rows on the first page, 20 on the next page e.t.c. and I would like change current page (like in a gridview).
I cant use gridview because my items should be displaing like:
(first row)
item1 item2
(second row)
item3 item4
...
(20th row)
item39 item40
first page prev. page next page last page.
but when I use griedview I got only:
(first row)
item1
(second row)
item2
...
(20th row)
item20
(because in the griedview next item dispalying only on the NEXT page)
or
(first row)
item1 item1
(second row)
item2 item2
...
(20th row)
item19 item20
(i tryed display two items in one itemtemplate but I got two same items in each row )
I really hope you undestand me and can help me. it is really important task for me and sorry my English.
thanx!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
You can achieve the functionality of the gridview paging in datalist using
'PagedDataSource'...at first attach your rows to PagedDataSource object and then bind the PagedDataSource to datalist...
Koushik
|
|
|
|
|
thanx!? but can you tell more deatils or show a simple example? i'm not sure i understood you
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
 Hey for eg:You have got a table(say 'dt') retrieved from the database...
Now bind it to PagedDataSource.
public partial class Default4 : System.Web.UI.Page <br />
<br />
{<br />
<br />
<br />
DataTable dt = null;<br />
protected int currentpage = 0;<br />
<br />
protected void Page_Load(object sender, EventArgs e)<br />
<br />
{<br />
<br />
#region Datalist binding with PagedDataSource<br />
<br />
<br />
PagedDataSource ps = new PagedDataSource();<br />
ps.DataSource = dt.DefaultView;<br />
ps.AllowPaging = true;<br />
<br />
ps.PageSize = 2;<br />
<br />
if (Request.QueryString["Page"] != null)<br />
{<br />
currentpage = Convert.ToInt32(Request.QueryString["Page"]);<br />
<br />
}<br />
else<br />
{<br />
currentpage = 1;<br />
}<br />
<br />
ps.CurrentPageIndex = currentpage - 1;<br />
Label1.Text = "Page:" + currentpage;<br />
<br />
if(!ps.IsFirstPage)<br />
{<br />
PrevLink.NavigateUrl = Request.CurrentExecutionFilePath +"?Page=" +(currentpage - 1);<br />
}<br />
<br />
if (!ps.IsLastPage)<br />
{<br />
NextLink.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" +(currentpage + 1);<br />
}<br />
<br />
<br />
<br />
<br />
DataList1.DataSource = ps;<br />
DataList1.DataBind();<br />
<br />
<br />
#endregion<br />
<br />
<br />
}
In the above example prevlink and nextLink are the Hyperlinks in your page
Koushik
|
|
|
|
|
thanx! i'll try it it in the evening and i'll post a result here. thanx!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
hi
i have some hyperlinks that show news title, i want when user click on hyperlink redirect to another page and pass some values to that page, but how to do ?
Note : i want when user click on hyperlink, i retrieve id of it and pass to another page, but in *.aspx how to retrieve ID from database and pass to another page by hyperlink ?
|
|
|
|
|
Hi,
You should write your logic of retrieving ID from the database in the "Page_Load" event and set the hyperlink's navigatUrl property.
hyperlink.NavigateUrl = "targetpage.aspx?ID" + ID.ToString();
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Also refer Urlencode functionality.
Regards,
Arun Kumar.A
|
|
|
|
|
Arun.Immanuel wrote: Also refer Urlencode functionality
Also refer Urlencode functionality
thanks .. my problem was solved, but how to use Urlencode functionality ??
plz give an example. thanks
|
|
|
|
|
hyperlink.NavigateUrl = "targetpage.aspx?ID" + Server.UrlEncode(ID.ToString());
Generally , "&" is the delimiter for querystrings.
So, if ID="Good&Bad" , then while retrieving U will get "Good" alone.
hope, I have explained it clearly.
Regards,
Arun Kumar.A
|
|
|
|
|
hi,i have one doubt regarding page class methods.my doubt is when to use RegisterStartupScript() and RegisterClientScriptBlock() methods.what is the major difference between the two methods?.please give suggestions for where those best suited.
|
|
|
|
|
I Don't know much about this two except
The RegisterClientScriptBlock method adds a script block to the top of the rendered page.
Whereas
The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised.
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|