I have a gridview which contains a column called 'klantnr' within this gridview I can edit and delete rows. But if there is a row where 'klantnr' is 0 then some command must tell not to delete this row. (course this row is always needed)
OR even beter.
If there is a row with klantnr is 0 then do not show this row in the gridview.
I don't have any code in VB.net only a template in asp.net with no commands yet.
This would make sense but I don't know in what command (rowdeleting?)
If (DirectCast(GridView1.Rows(1).FindControl("klantnr"),
Label).Text.ToString() = "0")
Then
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
dannx1986
Member
264 Points
106 Posts
Get information from specific cell in a gridview using VB.net
Oct 20, 2008 11:33 AM|LINK
Hello all!
I'm having trouble getting / find (specific) information out of a gridview.
I am using VB.net and an MS Access database.
Example:
I want Label2 to show 'klantnr exists' IF gridview1 has value 0 Else don't show anything.
( my gues is somthing like: If me.gridview1.rows.findcontrol("klantnr") = 0 Then me.label2.Text = "klantnr exists" but offcourse this doesnt work )
How can i find data inside gridview? using VB.net
Thanx in advanced
Danny Schouren
shivach7
Member
503 Points
114 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 20, 2008 11:41 AM|LINK
Explain Clearly and send ur source code
and i think you want to chek the item from gridview1 and the boundfield is textbox ................if so write this code o.w send ur source code okay
If(DirectCast(gridview1.rows.findcontrol("klantnr"),Textbox).Text.ToString()=="0")
then
label2.Text="exist"
else
not exist
Hopes this helps
Shiva
Contact me at shivach7@gmail.com
If(MyPost Helps You)
“Mark as Answer”
IamSrikanthR...
Participant
1764 Points
323 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 20, 2008 11:49 AM|LINK
Hi,
Please be little bit more accurate. You can the find the value of a cell in a gridview like
e.Row.Cells(0).Text; This can be done in a RowDataBound event of the GridView.
If you want to find a control then:
For example textbox then
TextBox txt=(TextBox)e.Row.FindControl("txtName");
then to read the value from the textbox u do txt.Text;
Other wise after the GridView has been built you can loop through the GridView Rows
like
foreach(GridViewRow gvRow in GridView1.Rows)
{
//Get the values of cells or find controls here.
}
Regards,
Iam Srikanth Reddy.
dannx1986
Member
264 Points
106 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 20, 2008 12:58 PM|LINK
Ok...
The actual thing i'm trying to do:
I have a gridview which contains a column called 'klantnr' within this gridview I can edit and delete rows. But if there is a row where 'klantnr' is 0 then some command must tell not to delete this row. (course this row is always needed)
OR even beter.
If there is a row with klantnr is 0 then do not show this row in the gridview.
I don't have any code in VB.net only a template in asp.net with no commands yet.
This would make sense but I don't know in what command (rowdeleting?)
If (DirectCast(GridView1.Rows(1).FindControl("klantnr"), Label).Text.ToString() = "0") Then
Label2.Text =
"do not delete this row" ElseLabel2.Text =
"row has been deleted" End IfThnx
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 22, 2008 05:58 AM|LINK
Hi dannx1986 ,
Yes , rowdeleting event is one good place to put your code in.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = this.GridView1.Rows[e.RowIndex]; Label lbl = row.FindControl("klantnr") as Label; if (lbl.Text == "0") { e.Cancel = true; } }Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
dannx1986
Member
264 Points
106 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 22, 2008 07:28 AM|LINK
Is this C# ? [8-)]
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 24, 2008 08:35 AM|LINK
Hi dannx1986,
You can convert it to vb.net using this tool : http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
dannx1986
Member
264 Points
106 Posts
Re: Get information from specific cell in a gridview using VB.net
Oct 24, 2008 12:26 PM|LINK
Thanx, thats a very useful tool!! [:)]