Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 3067 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET > Get the particular value in gridview using RowDataBound in c#.net ...
Kavi.Sirius

Get the particular value in gridview using RowDataBound in c#.net

Replies: 4 | Posted by: Kavi.Sirius on 4/26/2012 | Category: ASP.NET Forums | Views: 12591 | Status: [Member] | Points: 10  


hi

i have one problem to get the particular cell value in gridview, i am using RowDataBound method
below is my coding

protected void gvdApproverStatus_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[10].Text == "1")
{
Button btn = (Button)e.Row.FindControl("btnAccept");
btn.Visible = false;
}
}

}
catch (Exception ex)
{ }
}

but i cant to get the cells[10] value ,its shows the null ,
Thanks in Advance..

Regards
Kavi.n


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

GSM_GSV
GSM_GSV  
Posted on: 4/26/2012 3:09:21 AM
Level: Starter | Status: [Member] | Points: 25

Put this code in your gridview row data bound

c#
DataRowView drv = (DataRowView)e.Row.DataItem;

string catName = Convert.ToString(drv["YorColumnName"]);
if (catName == "1") {
Button btn = (Button)e.Row.FindControl("btnAccept");
btn.Visible = false;
}


vb
Dim drv As DataRowView = DirectCast(e.Row.DataItem, DataRowView)

Dim catName As String = Convert.ToString(drv("YorColumnName"))
If catName = "1" Then
Dim btn As Button = DirectCast(e.Row.FindControl("btnAccept"), Button)
btn.Visible = False
End If


Note :Do not use cell[0], cell[1] etc, instead use the column names to retrieve the data you want.

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Kavi.Sirius, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Kavi.Sirius
Kavi.Sirius  
Posted on: 4/26/2012 4:30:46 AM
Level: Starter | Status: [Member] | Points: 25

Thank u

Regards
Kavi.n

Kavi.Sirius, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

GSM_GSV
GSM_GSV  
Posted on: 4/26/2012 8:19:02 AM
Level: Starter | Status: [Member] | Points: 25

Mark as answer, if you are satisfied with the solution, so that its easy for others to recognize the post as resolved.

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Kavi.Sirius, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Oswaldlily
Oswaldlily  
Posted on: 4/27/2012 1:53:43 AM
Level: Starter | Status: [Member] | Points: 25

This s way for getting gridview cells...
string s1 ="";
string s2="";
foreach (GridViewRow brow in gv.Rows)
{
s1=((System.Web.UI.WebControls.Label)brow.FindControl("lblTimeStamp")).Text;
s2=((System.Web.UI.WebControls.Button)brow.FindControl("btn")).Text;
}

lblTimeStamp and btn are id where u used in design page.....
<asp:Label ID="lblTimeStamp " runat="server" Text="Customer Code" ToolTip="Customer Code"></asp:Label>

Kavi.Sirius, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 10:55:00 PM