Web Forms :: Toggle LinkButton In A GridView With A Loop
Jul 29, 2012
I am using GridView to display a list of forms submitted by a user and in one of the column I have a LinkButton which has got a conditional logic behind it to either display or hide it. The pseudo code for logic basically goes like this:If User has received a comment Show the link to the comment on the GridView. Else Hide LinkThis is the SQL that checks whether the user has got a comment for each submitted form:
Sql = "SELECT * FROM TableStudent INNER JOIN TableComment ON TableStudent .sID= TableComment .sID WHERE TableStudent .sID=@sID"
The SQL is working fine but I am having problem with looping through each form row to check if they have comment or not. Currently, the code hides the first row (correctly) but does not seem to be hiding the link for the following rows that does not have comments. I think my syntax for looping throw each row is incorrect.
For Each row As GridViewRow In gv1.Rows If ds.Tables(0).Rows.Count = 0 Then TryCast(gv1.Rows(0).FindControl("lnkBtnComment").FindControl("lnkBtnComment"), LinkButton).Visible = False Else TryCast(gv1.Rows(0).FindControl("lnkBtnComment").FindControl("lnkBtnComment"), LinkButton).Visible = True End IfNext
I revised the code as it seemed to be affecting only the first column and changed it to this:
For Each gvrow As GridViewRow In gv1.Rows If ds.Tables(0).Rows.Count = 0 Then TryCast(gvrow.FindControl("lnkDisplayComment"), LinkButton).Visible = False Response.Write(ds.Tables(0).Rows.Count) Else TryCast(gvrow.FindControl("lnkDisplayComment"), LinkButton).Visible = True Response.Write(ds.Tables(0).Rows.Count) End IfNext
Now the output for this has been if the associated form has any comment, it shows all the links and if the associated form has no comment, the comment links are hidden. And I have one applicant with two forms submitted; one of them has comment and the other does not. But my repsonse.write is returning 1 for both rows when I should clearly be 0 as it does not have any associated comment.
I was just after some help to put the following code into a loop. I have 6 div's with id's ImgDetails1 - ImgDetails6 and 6 buttons with id's 1 - 6
if 1 is pushed it should hide the other divs but ensure div1 is shown. the same applies for every other div.
I can do this the long way writing logic for each div but I am not the best with js and have failed at each attempt to put the code in a 1 - 6 loop to hide all divs except the one selected and make sure that is shown.
I am looking at building a grouping gridview, which I will know, will suit my needs. Therefore, I am not looking for a nested gridview. My answer is based upon an example I found at [URL]
However, what I am looking to do is to add a button to the group header row, which when pressed the rows within the group can either be shown or hidden.
I am trying to search the database using Data List and Item Template. I just want to loop the data's from database in a linkbutton and a lable row by row.
DataSet ds = new DataSet(); DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Description", typeof(string))); dt.Columns.Add(new DataColumn("Auctionno", typeof(string)));
Then when the user clicks an Edit button I run a script that enables all the checkboxes (which works fine), and then when the user then clicks on a checkbox the tick is appearing or disappearing as it should.
The problem I'm having is that when I try to read the value of the checkbox from the codebehind:
I would like to ask a question on the visual basic codes to loop the gridview to retrieve the values and based on the values, it will be provided as parameters to update to the database table using stored procedure.
Firstly, I have a gridview named grvProduct. The page (ui) will be loaded with data from the database with the use of stored procedures. And only certain values can be edited through the use of template in gridview. So based on those edited values, I'm supposed to pass these values as parameters to the stored procedure which will then update a database table.
Let say, I have 3 records retrieved from the database and displayed in the gridview. And I would like to edit a values in the 3 records, how do I do batch update and pass those parameters to the stored procedure? I went to debug and step through the visual basic codes and realised there were too many arguments specified because I actually loop the gridview.
Below is my visual basic codes:
[Code]....
Below is my Stored Procedure code: [Code]....
I believe it is the error in the looping of the gridview which results that I could not batch update the data/values.
How do I loop through a GridView (the actual GridView, not its data source) to check what's displayed in the first cell (a BoundField with int data) of every row?
Is it possible to loop through a gridview and based on if a checkbox is checked, then change the backcolor to that current row? I have gave a few attempts, but luck.
I have a Bulk Gridview(all rows are editable) I need to loop through.I need to get the text that's displayed in each of the textboxes in the gridview, my current code is this:
[Code]....
like this, I need to loop through the gridview, but instead of just getting the text in each column, I need to get the text from the textboxes. How can I do that?If i'm going to use findcontrol() then I need the ID of each control. the gridview is always created dynamically, which means I don't know the number of controls that's being created beforehand. So, how/where can I find the ID?Is there another way to extract data from the textbox, other than findcontrol()?
I need to make sure only one checkbox gets checked in a GridView. I have tried a solution on here, but I get an error. The other is looping through the checkboxes in the gridview to get the value, in this case, a date.
How do I loop the gridview to read or insert one row by one row?I have a database which has a Primary key. Currently,all the rows seems to appear at one time.Even when I use a counter,it did read one row from a textbox(which is for my testing to read one row) but in the database,it still inserts the whole rows from the gridview.I can't click button twice as it will occur an error "Primary Constraint".
I have a two gridviews that I populate it through some tables from a database.
In the same page I have a ASP:Button with onclick event.
When click is perform I wish to write a code that compares the old values of both gridviews (that retrieved from database), with the new values, and if changes were made then create the changes in the database.
I think that the best way is to loop every gridview sepertly, and compares it with the values in the database
How do I do that? Do you have a sample code that loops on gridview and compares with the old values to detect changes?
I want to add each value of 'k' to a gridview..If I have 10 values for 'k' (count=10), then I want to display a gridview with 10 rows...How can I do this?..
I need to loop through a GridView and get the values of a databound field. Then use those values in my update statement.
Here is the GridView:
[Code]....
And here is my UPDATE statement, which is actually just passing the values to a stored procedure:
[Code]....
Right now, I just have it grabbing the text from a label control, but I know that will not work as it only passes one value. I need to be able to update multiple rows based on the del_doc_num.
I am trying to add a LinkButton in a GridView that when clicked activates the the AJAX ModalPopupExtender to allow the User to Confirm if they want to Delete a Row.f they click Yes the Delete method should then take place. Unfortunately when I use a LinkButton when Yes is clicked to Confirm the deletion of a Row the LinkButtons click event is not fired.
I have a GridView, the first column it's a RadioButton template and the second it's a DropDownList Template, the number of rows depends on the user, I mean they are not static. I'm using the following JS function to get the row selected with the radiobuttons:
[Code]....
With this function I know which RadioButton was selected, now, I would like to get the DropDownList value or text of the selected row, I know I have to loop through every DropDownList to get an array of controls, but since they are something like ctl00_ContentPlaceHolder1_GVProducts_ctl02_DValsDropDown, I just don't know how to achive this through JS.
I have a gridview in which I add extra rows manually (besides the regular bound rows).The manually added rows do not have a textbox, they are just text.The normal rows hold a textbox "minprice".Now when the user clicks the NewGarage button I want to loop through the gridview and get the values in each row for the minprice textbox.
Gridview structure looks like this: MANUALLY_ADDED_ROW NORMALROW <= enter value here works MANUALLY_ADDED_ROW NORMALROW[code]...
How do I add a LinkButton to a GridView pager? The only way I can think of implementing this is to dynamically add the numeric pages in the code behind and add the LinkButton I require in the PagerTemplate. owever in the example illustrated when a user clicks a numeric Page number the numbers disappear and nothing fires. My GridView is in an UpdatePanel.
I want take value from gridview when Linkbutton from gridview cliked on link button clicked event.my code is
Protected Sub LinkStudentID_Click(ByVal sender As Object, ByVal e As EventArgs) ModalPopupExtender1.Show() Dim Val_StudentID As String = "" Dim Val_class As String = " Dim linkbtn As LinkButton = DirectCast(sender, LinkButton)
actually i am having a gridview control in my page..in that gridview i displayed the employee details and i provide view link button for every column in that gridview..my doubt is whenever i click the view link button in the gridview,the employee id will be get and pass it to other page and retrive the values using that employee id ..how to use.? I am using a code like this
<asp:TemplateField HeaderText ="View"> <ItemTemplate > <asp:LinkButton ID="LinkButton1" runat="server" Text="View" PostBackUrl='<%#"~/Default.aspx?empid="+Eval("empid")%>'></asp:LinkButton> </ItemTemplate> when i click the view button it will go to default page but the records are not displayed in the textbox..this is my default.aspx.vb code
I have a gridview in my aspx page, which is filled with data from generic list.
I want to add a checkbox and a link button in the grid, so that users can select the row and when users click on the link button, a new page is loaded with the items in the selected row.