hi
in my project i have a directors page which includes their picture information and filmography. I want to show filmography in different data presentation control than the other data. And i want to show it with this stored procedure:
select
Film from Films inner join Film_Director on Films.id=Film_Director .fid where yid=@idbut i have InCollection field in Films table and in my data presentation control i want to change the color of Film's Text by InCollection. If InCollection=true for that movie that row's text should be green if false should be red for example.
So which control is best for this situation? And which event should i use for changing color of text?
![]() |
0 |
![]() |
Datalist
Jai Ganesh. J , GSD ,India
Please Mark As Answer If my reply helped you.
![]() |
0 |
![]() |
ok and here is my datalist :
<asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <%# Eval("FilmAdi")%> </ItemTemplate> </asp:DataList>and my databinding code in cs:
string strConnString = ConfigurationManager.ConnectionStrings["DVDArsivConnectionString2"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(strConnString); SqlCommand sorgu = new SqlCommand(); sorgu.Connection = con; sorgu.CommandType = CommandType.StoredProcedure; sorgu.CommandText = "sp_Filmografi"; con.Open(); SqlDataAdapter sorgu1DA = new SqlDataAdapter(sorgu); sorgu1DA.SelectCommand.Parameters.AddWithValue("id", Convert.ToInt32(Request.QueryString["id"])); DataTable DTable = new DataTable(); sorgu1DA.Fill(DTable); DataList1.DataSource = DTable; DataList1.DataBind(); con.Close(); }
now in which event can i change <%# Eval("FilmAdi")%> 's text color? and what object should i use to do that?
![]() |
0 |
![]() |
elephantman:
now in which event can i change <%# Eval("FilmAdi")%> 's text color? and what object should i use to do that?
i tried like this. "aspx" page
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
InTheaters: <asp:Label ID="InTheatersLabel" runat="server" Text='<%# Eval("InTheaters") %>' ></asp:Label><br />
Title: <asp:Label ID="TitleLabel" runat="server" Text='<%# FormatTitle(Eval("Title"), Eval("InTheaters")) %>'></asp:Label><br />
<br /> </ItemTemplate>
</asp:DataList></div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [InTheaters], [Title] FROM [Movies]"></asp:SqlDataSource>codebehind
public string FormatTitle(Object title, object intheatres )
{
bool boolIntheatres = (bool)intheatres;
if (boolIntheatres == true)
{
return "<span style=color:green>" + title.ToString().ToUpper() + "</span>";
}
else
{
return "<span style=color:red>" + title.ToString().ToUpper() + "</span>";
}
}"intheatres" is boolean field. "title" is text field.
if the boolean is true then i change the color of the title to "green" or to "red"
Jai Ganesh. J , GSD ,India
Please Mark As Answer If my reply helped you.
![]() |
0 |
![]() |
protected void Page_Load(object sender, EventArgs e)now this is my data list:
<asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <asp:Label ID="TitleLabel" runat="server" Text='<%# FormatTitle(Eval("FilmAdi"),Eval("InCollection"))%>'></asp:Label> </ItemTemplate> </asp:DataList>and this is my cs code:
stringstrConnString = ConfigurationManager.ConnectionStrings["DVDArsivConnectionString2"].ConnectionString;
{
SqlConnection con = new SqlConnection(strConnString);SqlCommand sorgu = new SqlCommand();sorgu.Connection = con;
sorgu.CommandType =
CommandType.StoredProcedure;sorgu.CommandText = "sp_Filmografi";con.Open();
SqlDataAdapter sorgu1DA = new SqlDataAdapter(sorgu);sorgu1DA.SelectCommand.Parameters.AddWithValue(
"id", Convert.ToInt32(Request.QueryString["id"]));DataTable DTable = new DataTable();sorgu1DA.Fill(DTable);
DataList1.DataSource = DTable;
DataList1.DataBind();
con.Close();
}
public string FormatTitle(Object title, Object incollection){
bool boolincollection = (bool)incollection;if (boolincollection == true){
return "<span style=color:green>" + title.ToString() + "</span>";}
else{
return "<span style=color:red>" + title.ToString() + "</span>";}
}
i got error with this code the error is : Specified cast is not valid. (shown this line : bool boolincollection = (bool)incollection; )
and i have another question: if this error is gone i think with this code users can see InCollection field is true or false but i dont want to show it, i want to show it only colors if it is true only Fim name is shown with green color if it is false only Film name is shown with red color. so the above code (if it works) satisfies me or not?
![]() |
0 |
![]() |
elephantman:
FormatTitle(Object title, Object incollection){
bool boolincollection = (bool)incollection;if (boolincollection == true){
return "<span style=color:green>" + title.ToString() + "</span>";}
else{
return "<span style=color:red>" + title.ToString() + "</span>";}
}
is this variable a "incollection" is a "bit" datatype in sqldatabase ? if is then casting would not give error.
2. if u dont want "true" "false" value then dont display the item in the "itemtemplate" field
Jai Ganesh. J , GSD ,India
Please Mark As Answer If my reply helped you.
![]() |
0 |
![]() |
oh SORRY it was my mistake :( yes it was a bit field but because of added lately i forgot to fill the InCollection value of movies. Now it work really nice THANKS!
![]() |
0 |
![]() |