|
I am trying to solve this issue in the code behind file, but I am trying almost two days now without any success.
The thing is that the label is in templatefield within gridview and I am having hard time to solve how I can get to the label in the gridview, check the text and set the forecolor depending on the text.
If you have good example how I can solve this in code behind file I will be more then pleased to accept that.
Thanks, Laziale
|
|
|
|
|
Ahhh ok. So, from my experience, you're probably going to want to hook into the databind event on a row, find your label control using fincontrol on the row being passed and then change the colour there. Example:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label myLabel = (Label)e.Row.FindControl("yourlabel");
if (myLabel.Text == "Jack")
{
'change the colour here
}
}
There might be an easier way but that's just off the top of my head.
|
|
|
|
|
Looks like you are setting the Label text at runtime and server side. Why using a Eval container?
Directly in the server side, use a switch statment, based on various case , set the back/fore color of the label and also set the text!
|
|
|
|
|
I am trying this on button event:
for (int i = 0; i < gvPpl.Rows.Count; i++)
{
Label lblL = (Label)gvPpl.Rows[i].Cells[2].FindControl("lblFirstName");
}
but nothing comes up.
Can you give me some example how I can do that, and how I can set the forecolor afterwards. Eval container was there before I started working on this code.
Please advice if I can/need to use something else and still get the same data.
Thx, Laziale
|
|
|
|
|
Based on what now you say, that this is not an independant label and is in the GridView template field...
Here you go:
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblFirstName= (Label)e.Item.FindControl("lblFirstName");
if(lblFirstName.Text == "John")
lblFirstName.ForeColor=Color.Red;
else if(lblFirstName.Text == "Jim")
lblFirstName.ForeColor= Color.Blue;
}
}
Lastly, i would suggest to pick a book and read before mocing ahead with development. This is because 2-3 threads below you had been given almost 80% of the code and yet you are unable to get it.
|
|
|
|
|
First, thanks for your reply. I tried that thing too, but I am getting no value for the label. Here is what I have:
in the html part:
<div style="padding-left: 10px; padding-right: 10px; text-align: left; width:45%">
<asp:Label ID="lblFirstName" runat="server" Text='<%#Server.HtmlEncode(Eval("FirstName").ToString())%>'></asp:Label>
</div>
in the code behind:
protected void gvPpl_DataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < gvPpl.Rows.Count; i++)
{
Label lblL = (Label)gvPpl.Rows[i].Cells[2].FindControl("lblFirstName");
Label lblL1 = (Label)gvPpl.Rows[i].Cells[1].FindControl("lblFirstName");
Label lblL2 = (Label)gvPpl.Rows[i].Cells[0].FindControl("lblFirstName");
Label lblL3 = (Label)gvPpl.Rows[i].Cells[3].FindControl("lblFirstName");
}
}
I am trying with different cells, just in case I have the wrong cell, but that is not helping, all the labels have no text.
Any advice?
Thx, Laziale
|
|
|
|
|
Hi,
If you just want to change the forecolor, you can try this:
string test1 = "John";
string test2 = "Jim";
string testStr = Label1.Text;//source string
if (testStr.IndexOf(test1) > 0)
Label1.ForeColor = System.Drawing.Color.Red;
else if (testStr.IndexOf(test2) > 0)
Label1.ForeColor = System.Drawing.Color.Blue;
Hope it helps
modified 27-May-14 4:49am.
|
|
|
|
|
HI
Response.End () giving This Error
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Please How to solve?
|
|
|
|
|
This is becasue, the Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.
Resolution:
For Response.End , call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.
Find the full detail here:
ThreadAbortException [^]
|
|
|
|
|
Hi,
If you use
1. Response.End,you should try ApplicationInstance.CompleteRequest
2. Response.Redirect,please change it to Response.Redirect(String url, bool endResponse),set endResponse as false. For example,
Response.Redirect ("nextpage.aspx", false);
3. Server.Transfer,please change it to Server.Execute.
Hope this helps
modified 27-May-14 4:41am.
|
|
|
|
|
I divided my application into 2 different web apps. I have created a control in the first web app and i need to reference it in the second application. Is it possible to do so? I am trying to drag and drop the control but when debugging i am getting problems.
Thanks for your help.
|
|
|
|
|
First of all, whether it's a Custom control or a User control? Heading of your query says a usercontrol.
Had it been a custom control, you can include that as a reference and drag-drop it on your designer.
If it's a user control that too in another project, it would be difficult for you to refer. Either include that user control in your project where you need it or design a similar one.
|
|
|
|
|
Thanks for your reply. its a user control. The use of itis to have one control which could be used on both apps. Is there any solution for that please?
|
|
|
|
|
It's a file that can be found in your folders. Since you don't want to create a copy, design the directory of this file such that you can include it in both of your applications!
|
|
|
|
|
what kind of exception is this? how to rectify it?
|
|
|
|
|
Looks like you are trying to access data using a procedure or table valued function and getting this error.
If you check the stored procedure(SP) or table valued function(TVF) then you will find that they expect some parameters in order to run. You are calling TVF/executing SP without suppling those parameters.
Supply them and it will be resolved.
|
|
|
|
|
suppose i have button in my page and i want that when user click on that button then i will call gridview sort event
explicitly with proper parameter. is it possible if yes then please guide me with sample code.
thanks in advancetbhattacharjee
|
|
|
|
|
myGridview.Sort("Column1", SortDirection.Descending);
|
|
|
|
|
Store grids sorting somethng like this:
private SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set
{
ViewState["sortDirection"] = value;
}
}
OnClick event of the control:
protected void btnClick(object sender, EventArgs e)
{
ViewState["SortExpression"] = sortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, DESCENDING);
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, ASCENDING);
}
}
private void SortGridView(string sortExpression, string direction)
{
DataView dv = new DataView(dt);
dv.Sort = sortExpression + direction;
gvHours.DataSource = dv;
gvHours.DataBind();
}
|
|
|
|
|
both things is used to store value and can be access from any page. so what is actual difference between session and profile.thanks in advance tbhattacharjee
|
|
|
|
|
|
please help me in asp .net on clicking a button in left frame the data related to it has to appear in right.I want the code also.
http://www.treeview.net/treemenu/demos.asp
http://www.treeview.net/treemenu/3fr_beenthere.html
this the model in which i want that is with frames. but in this link it is provided in java script . but i want the coding in asp.net
|
|
|
|
|
Please post your requirement here. You will definitely get lots of positive responses.
|
|
|
|
|
u plz check the link in that model am designing my website. In that plz select frame layout. I want the coding in asp.net. some of my friends have suggested to use either ajax or javaScrpit. But my requirement is only in asp.net
|
|
|
|
|
You failed to get my point.
|
|
|
|