Thanks for your kind help.
I added a push button and OnItemCommand="HighLightME"
and on page behind i have
Public LastColoredIndex As
System.Web.UI.WebControls.DataGridCommandEventArgs
Sub HighLightME(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid1.ItemCommand
If Session("test") = 1 Then
Session("oObj").Item.BackColor =
System.Drawing.Color.Red
End If
e.Item.BackColor =
System.Drawing.Color.Green
LastColoredIndex = e
Session("oObj") = LastColoredIndex
Session("test") = "1"
End Sub
Only problem with this is when i select (press the
button)first row it change that row but when i select
second row,first row still green and second row is
green .
I want that when i select second row first row should
change back to original color and sec. one should be
green.
Do you have any idea how can i do it.
Thanks,
Hi Everyone,
I am new to asp.net and i want to develop small
application.
I have three control on form (Listbox,button and
Datagrid ).
I want to do the following.
1. When i clieck on row on datagrid i want this row to
be highlighted.
2. when i select some value on ListBox and press
button(>>) i want
that value to be added in grid under the selected
(highlighted) row.
Values in the datagrid and ListBox are same like
ClientID,ClientName.
Can anyone please tell me how can i do that.
Any help is much appriciate.
Thanks,
Pargat Gill
Post a follow-up to this message
Message 2 in thread
From: locitt (
[email protected])
Subject: Re: Please help
View this article only
Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
Date: 2004-02-03 16:12:13 PST
First, you should handles OnSelectedIndex event of
DataGrid, and stores the
selectedindex in Session. Then when click on the
button, retrieve the
SelectedIndex from Session and update to the current
selected row.
But remember to store your datasource (DataTable or
DataSet) that uses to
bind to the grid.
To select a row on click anywhere on datagrid item,
you need to add a
TemplateColumn and in ItemTemplate, add a button which
has CommandName is
Select. For instance, i named is btnSelectRow and it
is a linkbutton
private void OnItemDataBound(...)
{
if(e.Item.ItemType == ListItemType.Item
||e.Item.ItemType ==
ListItemType.AlternatingItem)
{
LinkButton b =
(LinkButton)e.Item.Cells[0].FindControl("btnSelectRow");
e.Item.Atttributes.Add("onclick",
this.Page.GetPostBackClientEvent(b, "");
}
}
private void BindData()
{
SqlDataAdapter da = new SqlDataAdapter();
...
DataTable ds = new DataTable("Name");
ds.Fill(ds, "Name");
DataGrid1.DataSource = ds.DefaultView;
DataGrid1.DataBind();
Session["MyDataSource"] = dt;
}
private void OnButtonClick()
{
DataTable dt = Session["MyDataSource"];
dt.Rows[DataGrid1.SelectedIndex].ItemArray.SetValue(0,
listbox.SelectedValue)
//...set more for other columns if you want.
DataGrid1.DataSource = ds.DefaultView;
DataGrid1.DataBind();
}
...And set the DataGrid1.AllowPaging = false; to avoid
mismatch the index
number between datagrid and your datatable.
Hope this help.
Here are some useful links
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechar
t/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp
http://www.datagridgirl.com/articles.aspx
..
Cheers.
locitt.
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/