|
Well, let's start with how you handle the click event. You've added an event handler to the link button and the source parameter of that handler is the actual LinkButton object that was clicked. How do you locate the cell? If you put a CommandArgument on the cell with a value like "5 3" where 5 is the row number and 3 is the column number, then it's easy to locate the cell in the grid. While still inside of your event handler you can set the fore and back colors of the cell and link button.
Logifusion[^]
|
|
|
|
|
I have no event handler - all I want is a hyperlink which I will pass a Request.FilePath based on whether or not the current background color is black or white. Once I pass along this info I will check it based on those values and color it the opposite color.
All I am really looking for is the actual syntax to locate the control as i already know the row & cell I am just not sure how to write the actual line to take the table, row & cell info and then put the control name(e_link) and change the forecolor.
I have this:
MyTable.Rows(i + 1).Cells(k + 1).Controls.Item(0).FindControl(CType(("e_link"), HyperLink))
I just need the proper way to write this line? The control exists already in the cell - I just need to access it and change its forecolor to black. I am new to this so it is probably something very simple.
Thanks, tammy
|
|
|
|
|
I think you're making this more difficult than it has to be. So, I tried doing this myself. I created a web page with a table in it. In the code behind I have this:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To 10
Dim tr As TableRow = New TableRow
Me.Table1.Rows.Add(tr)
For j As Integer = 0 To 10
Dim tc As TableCell = New TableCell
tr.Cells.Add(tc)
Dim lb As LinkButton = New LinkButton
lb.ForeColor = Color.Blue
lb.Text = "EDIT"
lb.CommandArgument = i.ToString + " " + j.ToString
AddHandler lb.Click, AddressOf lb_Click
tc.Controls.Add(lb)
Next
Next
End Sub
Private Sub lb_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lb As LinkButton = CType(sender, LinkButton)
Dim s() As String = lb.CommandArgument.Split(" ".ToCharArray)
Dim row As Integer = Integer.Parse(s(0))
Dim col As Integer = Integer.Parse(s(1))
Dim tc As TableCell = Me.Table1.Rows(row).Cells(col)
tc.BackColor = Color.Black
lb.ForeColor = Color.Black
End Sub
I made the forecolor for the linkbutton blue because I couldn't see the table. But, I think you get the idea.
Logifusion[^]
|
|
|
|
|
Hi Dustin (thank you so much for all the help)
Unfortunately there is no linkbutton but it is a hyperlink instead so it will not accept a CommandArgument.
I have this:
**e_link = CType(FindControl(e_link.ID), HyperLink)
e_link.ForeColor = System.Drawing.Color.Black
I am receving this error :
**Object reference not set to an instance of an object
Does this mean it can't find the control in question? I passed the row and column id to string as the ID earlier when I originally set up the table.
e_link.ID = "Row=" & i.ToString & "Column=" & k.ToString
Everything is working great except once I loop through my third datatable to fill in the 'black' selected cells against my data I still have the hyperlink EDIT in white.
The two lines above I think are close to changing it but obviously my syntax is wrong somewhere along the line. . . . . .
Thx, Tammy
|
|
|
|
|
widget1 wrote: e_link = CType(FindControl(e_link.ID), HyperLink)
Has e_link been initialized in this statement? You're asking for e_link.ID . That'll throw a null exception if e_link is not initialized.
Logifusion[^]
|
|
|
|
|
I have these loops above it all:
These loops build my table underneath my customized column headers , showing the whole table with the whole grid with white cells and all white hyperlinks one in each cell.
For i As Integer = 0 To dtassessment.Rows.Count - 1
headerrow = New TableRow
headerrow.ID = i.ToString
headerCell = New TableCell
headerCell.Text = dtassessment.Rows(i)("Name").ToString
headerCell.ApplyStyle(tableStyle)
headerrow.Cells.Add(headerCell)
dtoutcomes = Outcome.GetAll(m_connString)
For k As Integer = 0 To dtoutcomes.Rows.Count - 1
'this line fills in the grid on my table
'it also puts a hyperlink in each cell
Dim bodyCell As TableCell
bodyCell = New TableCell
Dim e_link As HyperLink = New HyperLink
e_link.ForeColor() = System.Drawing.Color.White
e_link.ID = "Row=" & i.ToString & "Column=" & k.ToString
e_link.Text = "EDIT"
e_link.NavigateUrl = "Default.aspx"
bodyCell.Controls.Add(e_link)
headerrow.Cells.Add(bodyCell)
Next
MyTable.Rows.Add(headerrow)
Next
headerrow.ApplyStyle(tableStyle)
I next go through my third datatable looking for matches in column and row values and color the cell accordingly. I also want to color the hyperlink inside this cell to match the background color.
'this section brings in my table data and loops through to find matches and place accordingly
For t As Integer = 0 To dttabledata.Rows.Count - 1
For i As Integer = 0 To dtassessment.Rows.Count - 1
If CInt(dttabledata.Rows(t)("Assessment_id")) = CInt(dtassessment.Rows(i)("Assessment_id")) Then
For k As Integer = 0 To dtoutcomes.Rows.Count - 1
If CInt(dttabledata.Rows(t)("Outcome_id")) = CInt(dtoutcomes.Rows(k)("Outcome_id")) Then
MyTable.Rows(i + 1).Cells(k + 1).BackColor = System.Drawing.Color.Black
MyTable.Rows(i + 1).Cells(k + 1).HorizontalAlign = HorizontalAlign.Center
MyTable.Rows(i + 1).Cells(k + 1).ForeColor = System.Drawing.Color.Black
e_link = CType(FindControl("e_link.ID"), HyperLink)***
e_link.ForeColor = System.Drawing.Color.Black
End If
I think I am having the problem that the e-link.ID created above does not hold the value through to the next set of loops?? Not sure how to overcome this problem. How can I maintain the ID value to my next set off loops?
Thx, t
|
|
|
|
|
widget1 wrote: e_link = CType(FindControl("e_link.ID"), HyperLink)
You declare e_link above inside of two for loops. How does this line even compile?
Logifusion[^]
|
|
|
|
|
I am not sure why but won't vb.net compile and then cause the runtime error versus C# which would not even compile? I declared and initialized above the loops now and now I am getting a runtime error on the next line:
**e_link.ForeColor = System.Drawing.Color.Black
Someone told me a linkbutton causes a postback and there are a lot of them on this table so a hyperlink only causes a page refresh which is better in this case.
How can I hold the ID value from the first set of loops into the second?
This is the first thing I have ever made with asp.net and vb.net for that matter.
Tammy
|
|
|
|
|
widget1 wrote: a linkbutton causes a postback and ... a hyperlink only causes a page refresh
Those things are the same in your case. A typical hyperlink should send you to a new page, but you're detecting that it was clicked and handling it server side, which means the form is being submitted.
widget1 wrote: How can I hold the ID value from the first set of loops into the second?
Where you do this:
e_link.ID = "Row=" & i.ToString & "Column=" & k.ToString
You are creating the ID. Simply copy the code you use to create that ID into the second loop:
e_link = CType(FindControl("Row=" & i.ToString & "Column=" & k.ToString), HyperLink)
Logifusion[^]
|
|
|
|
|
Ok I did that but I am still getting this error:
Object reference not set to an instance of an object.
It is highlighting this line:
Line 151: e_link.ForeColor = System.Drawing.Color.Black
I have no idea what is going on excpet I think it is not recognizing the hyperlink located in that cell.
Tammy
|
|
|
|
|
Well, the way you're doing this is going to be difficult. The page might not recognize the control yet enough to find it for you. So you might try going to the table itself:
e_link = CType(MyTable.Rows(i).Cells(k).Controls(0), HyperLink)
Logifusion[^]
|
|
|
|
|
Honestly, I still think you're making this too difficult. You're chaning the IDs of HyperLink s to overcome the fact they don't have a CommandArgument like LinkButton . Where LinkButton produces the same results and is much easier to use in this case.
Logifusion[^]
|
|
|
|
|
hi every one i have a problem, i have developed an asp.net application in which in one page i am showing data in grid and on clicking ID in grid it is opening a pop up window in which i can do some changes in the data base based on that id...
every thing is working fine page is refereshing also on clicking save button on the pop up window but my problem starts ... if i click on the back button of the browser window that pop up window automatically popup and all the fields are filled on the bases of id which i have selected earlier
so how do i solve this problem
plez suggest some answer...
Rohit Daga
|
|
|
|
|
Disable the Back Button click of the browser.U will find Javascript code for the same on google.
Thanks and Regards.
|
|
|
|
|
or you can invalidate pages in history.
in .NET 2.0 it is done by this line of code:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
|
|
|
|
hi all
i need help from all of u ,my question is,i add checkbox in datagrid and check some or all check box in datagrid and click delete button then those datagrid rows are delete from database.
Thanx in advance
your
peter
|
|
|
|
|
According to what i understood,this is how u can implement
foreach (DataGridItem dg in this.dgApproval.Items)
{
int i = 0;
//u use a for loop like this to find the template column of checkbox in data grid
if(((CheckBox)(dg.FindControl("CheckBox1"))).Checked == true)
{
//here i am retreiving the second column of datagrid as i neeeded it
//first column in data grid is the 0th column
string build_desc1=dg.Cells[1].Text.ToString();
//do what u want here... like i have written update query here
string query;
string query2;
query = "update build_master set approval_flag ="+ i +" where build_desc = '"+ build_desc1+"' ";
}
//make sure you bind the grid again to reflect the changes
BindGrid();
}
Happy Programming
Jiny
-- modified at 8:54 Friday 23rd June, 2006
|
|
|
|
|
How do i write javascript to call dll or exe in asp.net web application?
nevinda
|
|
|
|
|
|
How to access the dynamically created ASP.NET 2.0 controls
|
|
|
|
|
Page.FindControl(string controlId);
|
|
|
|
|
Thanks but i found solution, anyway thanks 4 ur time
|
|
|
|
|
|
Thanks 4 u reply and ur link is very usefull and i have found solution in this way u suggested me....
|
|
|
|
|
Hello,
I posted something similar to this post before but this is slightly different.
The GridView gets populated and in the _RowDataBound event the Accept button(select CommandField button) gets replaced by a text value if there is one as shown below:
The find button populated the GridView correctly and Accept button is replaced with a text where necessary but not sure why when the checkbox on the page is clicked on, then ALL the Accept buttons are shown on the GridView (Which is incorrect).
The check box control only shows a label.
Thanks
If (e.Row.RowType = DataControlRowType.DataRow) Then
'show the clinic code since there is a start date other wise just show the Accept button...
'If Not (e.Row.DataItem("c_start_date").ToString() Is Nothing) Then
If Not (e.Row.DataItem("c_start_date").ToString() = "") Then
e.Row.Cells(9).Text = e.Row.DataItem("c_clinic_code").ToString() 'Change ur text here
End If
End If
|
|
|
|