Last post Oct 24, 2008 01:26 PM by dannx1986
Oct 20, 2008 12:33 PM|dannx1986|LINK
I'm having trouble getting / find (specific) information out of a gridview.
I am using VB.net and an MS Access database.
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
Oct 20, 2008 12:41 PM|shivach7|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
Hopes this helps
Oct 20, 2008 12:49 PM|IamSrikanthReddy|LINK
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
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
foreach(GridViewRow gvRow in GridView1.Rows)
//Get the values of cells or find controls here.
Oct 20, 2008 01:58 PM|dannx1986|LINK
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?)
Label).Text.ToString() = "0")
Oct 22, 2008 06:58 AM|Samu Zhang - MSFT|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;
Oct 22, 2008 08:28 AM|dannx1986|LINK
Is this C# ? [8-)]
Oct 24, 2008 09:35 AM|Samu Zhang - MSFT|LINK
You can convert it to vb.net using this tool :
Oct 24, 2008 01:26 PM|dannx1986|LINK
Thanx, thats a very useful tool!! [:)]