[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP.NET GridView RowDataBound event

Posted on 2010-09-23
5
Medium Priority
?
811 Views
Last Modified: 2012-05-10
How to get access to the cell using column name.
Thanks.


0
Comment
Question by:quasar_ee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 1336 total points
ID: 33750789
The method below isn't so much based on gridview column name but instead the dataitem name(database column name).
Don't forget to run a check to see if the value is dbnull

Hope this helps,
Dustin
If e.Row.RowType = DataControlRowType.DataRow Then
 ' you can use a two line method 
      Dim rowView As DataRowView = CType(e.Row.DataItem, DataRowView)
      ' Retrieve the state value for the current row. 
      Dim state As String = rowView("state").ToString()

'or a one liner
Dim state1 As String = DataBinder.Eval(e.Row.DataItem, "state")
end if

Open in new window

0
 
LVL 16

Assisted Solution

by:MikeMCSD
MikeMCSD earned 664 total points
ID: 33751014

use : "(DataBinder.Eval(e.Row.DataItem, "fieldName")"

protected void grid1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      // example :
      if ((DataBinder.Eval(e.Row.DataItem, "fieldName")).ToString() == "Joe"
      {
        // to put field contents into a label:
        Label link1 = (Label)e.Row.FindControl("lblLink1");
        link1.Text = (DataBinder.Eval(e.Row.DataItem, "fieldName")).ToString()

    ....

Open in new window

0
 
LVL 14

Assisted Solution

by:Dustin Hopkins
Dustin Hopkins earned 1336 total points
ID: 33753084
Oops didn't notice the language.
if (e.Row.RowType == DataControlRowType.DataRow) {
// you can use a two line method 
	DataRowView rowView = (DataRowView)e.Row.DataItem;
	// Retrieve the state value for the current row. 
	string state = rowView["state"].ToString();

	//or a one liner
	string state1 = DataBinder.Eval(e.Row.DataItem, "state");
}

Open in new window

0
 

Author Comment

by:quasar_ee
ID: 33755603
Thank you.
Do you know how to get access to the Cell object in e.Row.Cells collection using DataView column name or database column name?
0
 

Author Closing Comment

by:quasar_ee
ID: 33843827
thx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question