Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello everyone...

i have this gridview here that is being populated by data from oracle database.the first two columns are circle and criticality containing character values(that do not change)..other columns have numeric values that are 0 or any positive number....my question is how can i add hyerlink to these cells which contain only positive numeric value??? each time the query is run, the numeric values change....there can now be a number where there was a zero and vice versa....am giving a view of the table below...
any suggestion anyone???
thank you so much...:)

circle criticality val1 val2 val3
abc A--------------0 1 2
abc B--------------0 0 0
abc C--------------5 0 0
Posted

Have item template field for circle as linkbutton and itemtemplate field for your values as Label and in gridView_RowDataBound check the value of the label if the value is greater that 0 then enable the link and if the value is 0 then disable the link.

Following example explains the words-----

C#
protected void gridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{

//make sure to have lblValue1 and lnkBtn as itemtemplate in your grid

Label lblValue= (Label)e.Row.FindControl("lblValue1");
LinkButton lnkBtn= (LinkButton)e.Row.findControl("lnkBtn");

if(Convert.ToInt32(lvlValue.Text)>0)
{
lnkBtn.enabled=true;
}
else
{
lnkBtn.enabled=false;
}

}




I guess it helps you....
 
Share this answer
 
v3
well, I did it like this...
C#
HyperLink l = new HyperLink();
                            l.Text = gr.Cells[2].Text;
                            l.NavigateUrl = "target_page.aspx";

                            if (gr.Cells[2].Controls.Count > 0)
                            {
                                while (gr.Cells[2].Controls.Count > 0)
                                {
                                    l.Controls.Add(gr.Cells[2].Controls[0]);
                                }
                            }
                            else
                            {
                                l.Text = gr.Cells[2].Text;
                            }
                            gr.Cells[2].Controls.Add(l);

i found this solution on net....made this cell value to move through loop for multiple columns......thank you Raj Parashar for your help...:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900