473,409 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

grid view and datagrid

I want to be able to replicate this datagrid code for a gridview.
Basically I need to set the colour of my link buttons and set the text
depending upon the value of a text box :

public void dgUserList_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
//First, make sure we're NOT dealing with a Header or Footer row
if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer)
{
LinkButton EditButton = (LinkButton)e.Item.Cells[9].Controls[0];
EditButton.ForeColor = Color.Blue;

LinkButton DeactivateButton =
(LinkButton)e.Item.Cells[10].Controls[0];
DeactivateButton.ForeColor = Color.Blue;

string strActive =
Convert.ToString(DataBinder.Eval(e.Item.DataItem," Active"));

Any ideas would be appreciated.
CheckBox chkActive = (CheckBox)e.Item.FindControl("chkActive");

if (strActive == "True")
{
chkActive.Checked = true;
DeactivateButton.Text = "Deactivate";
}
else
{
chkActive.Checked = false;
DeactivateButton.Text = "Activate";
}
}
}

*** Sent via Developersdex http://www.developersdex.com ***
May 22 '06 #1
3 2363
"Mike P" <mi*******@gmail.com> wrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...

Firstly, rename your dgUserList object to gvUserList

public void dgUserList_ItemDataBound(object sender, DataGridItemEventArgs
e) protected void gvUserList_RowDataBound(object sender, GridViewRowEventArgs
e)

if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer) if (e.Row.RowType == DataControlRowType.DataRow)

LinkButton EditButton = (LinkButton)e.Item.Cells[9].Controls[0]; LinkButton EditButton = (LinkButton)e.Row.Cells[9].Controls[0];

CheckBox chkActive = (CheckBox)e.Item.FindControl("chkActive");

CheckBox chkActive = (CheckBox)e.Row.FindControl("chkActive");
The rest should be obvious from the above.
May 22 '06 #2
Thanks Mark...you couldn't help me convert this piece of code could you?
I'm having problems with the e.Item parts and the DataKeys stuff.

if (e.CommandName == "ActivateDeactivate")
{
int intActivate = 0;

CheckBox cb = new CheckBox();

cb = (CheckBox)e.Item.FindControl("chkActive");

if (cb.Checked.ToString() == "True")
{
intActivate = 0;
}
else
{
intActivate = 1;
}

int key = (int)GridView1.DataKeys[e.Item.ItemIndex];
SqlConnection con = new
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings["Xe
roxConnectionString"]);
con.Open();

SqlCommand cmd = new SqlCommand("update userlogin set Active
= " + intActivate.ToString() + " where userkey = " + key, con);
cmd.ExecuteNonQuery();
GridView1.EditItemIndex = -1;
BindData();
con.Close();
}

*** Sent via Developersdex http://www.developersdex.com ***
May 22 '06 #3
"Mike P" <mi*******@gmail.com> wrote in message
news:e7**************@TK2MSFTNGP05.phx.gbl...
I'm having problems with the e.Item parts and the DataKeys stuff.


Like I showed you earlier, e.Item inDataGrids becomes e.Row in GridViews...
May 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
4
by: Filippo Pandiani | last post by:
I have a grid that shows the file list from a folder. On the postback, how do I get a Dataset from this grid? Thanks, Filippo.
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
3
by: Simon Harris | last post by:
Hi All, I have a data grid which displays country names. I now wish to display the country flag images above the names. Can someone please advise how I display an image in a datagrid? I have a...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
10
by: John Wilson | last post by:
My app produces some long datatables to display in a grid. So I put them in a div so users can scroll. But the grid headers scroll out of view. I would like to stop them doing this. Can I fix them...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
2
by: probashi | last post by:
Hi, Using the SqlDataSource/SelectParameters/ControlParameter one can easily bind a Grid View with a list box (or any other controls), pretty cool, but my list box is multi select. My...
4
by: kavithadv | last post by:
hi Please help me i want to fix a column in grid view i used style for locking the column since i am setting the position as relative its not working properly i have given my code below ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.