|
Please Correct the formatting of your post. Its breaking the page ! Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Try with this :
You need to do this in RowDataBound Event of GridView .
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblFirstName= (Label)e.Item.FindControl("lblFirstName");
if(lblFirstName.Text == "MyText")
lblFirstName.ForColor=mycolor;
}
} Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Thanks for all your help.
I have one question, since I am trying to figure out the color of the label in the page_load event, is there anyway how I can assign the color depending from the text in that label?
Thx, Laziale
|
|
|
|
|
laziale wrote: since I am trying to figure out the color of the label in the page_load event, is there anyway how I can assign the color depending from the text in that label?
Why you are trying out in Page_Laod. If you want to check for each and every row of gridview, you need to check it in RowDataBound Event only.Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
cause I want to display the proper color before the site is rendered on the screen. Is there a way how I can trigger that event in the Page_Load?
Thanks, Laziale
|
|
|
|
|
Do you understand the page life cycle? Read about it here[^].
In your page load event you want to set the DataSource property of your grid and call DataBind. Hopefully in your init method you setup an item data bound event handler. When DataBind is called, for each row being added to the gridview your data bound event handler will be called. There you set your colors. After all of that is done, Render gets called for the page which generates all the HTML from your page and code which gets sent to your user's browser.Don't blame me. I voted for Chuck Norris.
|
|
|
|
|
For changing the color,just change the color in rowdatabound only.It'll suffice your purpose.
After pageload,you must have assigning some datasource.then, your rowdatabound event will be called for each row.In this event,you can modify the color based on the text. After it page will render and your changes will refelct on the screen.
So you dont need to do this at pageload.Cheers!!
Brij
|
|
|
|
|
nothing is happening with that one, I have the event set but its not triggered at all. The page loads without triggering that event.
But thanks for your help anyway.
Laziale
|
|
|
|
|
laziale wrote: nothing is happening with that one, I have the event set but its not triggered at all.
Did you specified the event with gridview in aspx page ?Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
ok, there were two events for the same thing, that why it wasn't triggered. Now its triggered, but for some reason when I am stepping in to the code the label property doesn't get the text. Its left empty.
Here is the code:
void gvOrderProductVariants_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblFirstName= (Label)e.Row.FindControl("lblFirstName");
if (lblFirstame.Text.Contains("John"))
lblFirstName.ForeColor = System.Drawing.Color.Red;
}
}
Please tell me if I am doing something wrong.
Thx, Laziale
|
|
|
|
|
hi,
Here is an example:
gridview_OnDataBound(){
Label label1 = e.Item.FindControl("lable1") as Label;
Label label2 = e.Item.FindControl("lable2") as Label;
if(lable1.Text == "1") {
label2.ForeColor = "red";
}else if(lable1.Text == "2"){
label2.ForeColor = "blue";
}
}
Hope it helps
modified 27-May-14 4:49am.
|
|
|
|
|
I can't get to the 'e' argument since the databound event is using EventArgs.
Thanks for your help though
|
|
|
|
|
<asp:SqlDataSource ID ="myid" ConnectionString = "server = .\sqlexpress; integrated security = True; database = northwind;"
SelectCommand = "select LastName from employees " runat = "server" />
<asp:BulletedList runat="server" DataSourceID = "myid"/>
and its output
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
* System.Data.DataRowView
i want it to be LastName not its default ToString();
|
|
|
|
|
You are missing DataTextField binding.
Specify the control's DataSourceID property. Specify at the very least the required DataTextField. The value of each record in this field will then be displayed as the text of each item in the list.
So, you need to do:
<asp:BulletedList runat="server" DataSourceID = "myid" DataTextField="LastName" />
|
|
|
|
|
Also set DataTextField of your BulletedList, because without it,How BulletedList list come knowthat what to show.Use following code
<asp:BulletedList runat="server" DataSourceID = "myid" DataTextField="LastName"/>
Let me know if still face problem.Cheers!!
Brij
|
|
|
|
|
The same answer has been posted by Sandeep. Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Just see the timings when I started replying, no answer was there... Cheers!!
Brij
|
|
|
|
|
Hmm... that may be and sometime it's happens too. But that does not mean that you vote the post "1" without any reason (If you voted).
Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Hi,
I'm trying to solve this issue for 1 week, and i can't seems to solve it.
I search through net, they say its most probably because of permission access.
I have given full rights for all the users, including "Everybody", but error still remains.
This error only will occurs after upload twice, or 3 times, or on the 5th file of uploading. Its random. So i suspect its not the permission access problem.
Below is summary of my codes.
System.Drawing.Image image = ResizeImageImg(fp.PostedFile.InputStream, ImageWidth, ImageHeight);<br />
image.Save(savepath, ImageFormat.Jpeg);
<br />
image.Dispose();
private System.Drawing.Image ResizeImageImg(Stream streamImage, int maxWidth, int maxHeight)<br />
{<br />
Bitmap originalImage = new Bitmap(streamImage);<br />
int newWidth = originalImage.Width;
int newHeight = originalImage.Height;
double aspectRatio = (double)originalImage.Width / (double)originalImage.Height;<br />
<br />
if (aspectRatio <= 1 && originalImage.Width > maxWidth)<br />
{<br />
newWidth = maxWidth;<br />
newHeight = (int)Math.Round(newWidth / aspectRatio);<br />
}<br />
else if (aspectRatio > 1 && originalImage.Height > maxHeight)<br />
{<br />
newHeight = maxHeight;<br />
newWidth = (int)Math.Round(newHeight * aspectRatio);<br />
}<br />
<br />
System.Drawing.Image CropedImage = new Bitmap(newWidth, newHeight);<br />
using (Graphics grp = Graphics.FromImage(CropedImage))<br />
{<br />
grp.SmoothingMode = SmoothingMode.HighQuality;<br />
grp.InterpolationMode = InterpolationMode.HighQualityBicubic;<br />
grp.PixelOffsetMode = PixelOffsetMode.HighQuality;<br />
grp.DrawImage(originalImage, 0, 0, newWidth, newHeight);<br />
<br />
grp.Dispose();<br />
originalImage.Dispose();<br />
}<br />
<br />
return CropedImage;<br />
}
Please help guys. If you do have any simple working codes, please share.
Thx.
|
|
|
|
|
Ok, could you tell us what error is being raised and have you debuggd to ensure that savepath and Image are valid objects when being passed at that point?
|
|
|
|
|
hi thx for the reply.
yes i have check properly. the saving path is "C:\Inetpub\wwwroot\Personal\Web\Image\test.jpg"
If the path is incorrect, its suppose hit error on the 1st place rite? but this GDI+ error message appears after few times of upload.
any idea?
thx.
|
|
|
|
|
Hi
I Want Multiple Email Ids validating using Regular Expression Validator. Every mail id should be seprate with comma and space for example. dan@g.com, mike@g.com, matt@g.com .
Regards
D.V.Mallikarjuna Guptha
|
|
|
|
|
|
www.regexlib.com has multiple regular expressions that'll do what you want, pick one.
|
|
|
|
|