Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
treilly via DotNetMonster.com #1
Takes two clicks to fire event?? Please help!
Hey guys,
This is really starting to annoy me. In short, I have a datagrid with a
buttoncolumn in the first column. Once a user clicks on a button in this
column, it fires the OnItemCommand correctly. In the OnItemCommand function,
I then replace the control that fired with a different one in order to
perform some other actions the next time it is clicked. Everything works as
expected, except it takes two clicks in order to fire the events which
totally screws up my datagrid.
After doing some research on this problem, I THINK I may need to add the
RaiseBubbleEvent and OnBubbleEvent functions to my code. The only problem is,
I've tried doing that with no success. Perhaps I am doing it incorrectly.
Can anyone shed some light on where I may need to add the RaiseBubbleEvent
(this, e) line as well as where to place my OnBubbleEvent function?
I can't think of any other reason why it would take two clicks to fire the
event.
I wanted to post this question without including code because I know how
terrible it is looking through somebody else's code - but I don't think I
could have done it without confusing myself as well as others.
Thanks for the help in advance!
-TR
Here is my code for the OnItemCommand handler:
protected void ItemClick(Object source, DataGridCommandEventArgs e)
{
switch (e.CommandName) //depending on which button the user
clicked
{
case "cmdArrow": //expand the item to show more info,
picture
{
LinkButton downArrow = new LinkButton(); //replace
the old control with the new control
downArrow.ID = "downArrow";
downArrow = (LinkButton)e.Item.Cells[0].Controls[0];
downArrow.Text = "<img src='arrowdownVA.GIF'
border='0'/>";
downArrow.CommandName = "downArrow";
string name; //temporary storage variables
string title;
string location;
string phone;
string emladdress;
string email;
string about;
string imageURLwithTag;
string imageURL;
LinkButton linkBtn = (LinkButton)e.Item.Cells[1].
Controls[0];
name = linkBtn.Text;
title = e.Item.Cells[2].Text;
location = e.Item.Cells[3].Text;
phone = e.Item.Cells[4].Text;
HyperLink hyperLnk = (HyperLink)e.Item.Cells[5].
Controls[0];
emladdress = hyperLnk.Text;
email = "<a href='mailto:" + emladdress + "'>" +
emladdress.ToLowerInvariant() + "</a>";
about = e.Item.Cells[6].Text;
imageURLwithTag = "<img src=" + e.Item.Cells[7].Text
+ "/>"; //width='100px' height='80px'
imageURL = e.Item.Cells[7].Text;
TableCellCollection tcc = e.Item.Cells; //clear all
but the first column's controls
int totalCols = tcc.Count;
for (int i = 1; i < totalCols - 1; i++)
{
e.Item.Cells.RemoveAt(0);
}
e.Item.Cells[0].Controls.Add(downArrow); //add the
new control to first column of datagrid
e.Item.Cells[1].ColumnSpan = 5; //column needs to
span 5 in order to show more info
e.Item.Cells[1].Text = "<div class='imageHolder'>" +
imageURLwithTag + "</div>";
e.Item.Cells[1].Text += "<div class='infoBlock'><div
class='expandedName'>" + name + "</div><br/>"
+ "<div class='expandedTitle'>" + title +
"</div><br/>"
+ "<div class='expandedLocation'>" + location +
"</div><br/>"
+ "<div class='expandedPhone'>" + phone +
"</div><br/>"
+ "<div class='expandedEmail'>" + email +
"</div></div>"; ;
e.Item.Cells[1].Text += "<div class='expandedAbout'>"
+ about + "</div>";
//save this row in sessionstate
dirMember member = new dirMember(name, title,
location, phone, emladdress, about, imageURL);
Session[e.Item.ItemIndex.ToString()] = member;
break;
}
case "downArrow":
{
LinkButton cmdArrow = new LinkButton(); //replace the
old control with the new control
cmdArrow.ID = "cmdArrow";
cmdArrow = (LinkButton)e.Item.Cells[0].Controls[0];
cmdArrow.Text = "<img src='arrowVA.gif' border='0'/>";
cmdArrow.CommandName = "cmdArrow";
TableCellCollection tcc = e.Item.Cells; //clear all but
the first column's controls
int totalCols = tcc.Count;
for (int i = 1; i < totalCols - 1; i++)
{
e.Item.Cells.RemoveAt(0);
}
e.Item.Cells[0].Controls.Add(cmdArrow); //add the
control to first column of datagrid
//restore member's info to original columns
dirMember member = (dirMember)Session[e.Item.ItemIndex.
ToString()];
for(int i = 1; i < DataGrid1.Columns.Count - 1; i++)
//return columns to original spans
{
TableCell tc = new TableCell();
tc.ColumnSpan = 1;
e.Item.Cells.AddAt(i, tc);
}
LinkButton collapsedName = new LinkButton();
collapsedName.CommandName = "cmdArrow";
collapsedName.Text = member.Name;
e.Item.Cells[1].Controls.Add(collapsedName);
e.Item.Cells[2].Text = member.Title; //place the info
from session state back into columns
e.Item.Cells[3].Text = member.Location;
e.Item.Cells[4].Text = member.Phone;
LinkButton collapsedEml = new LinkButton();
collapsedEml.Text = "<a href='mailto:" + member.
Emladdress + "'>" + member.Emladdress + "</a>";
e.Item.Cells[5].Controls.Add(collapsedEml);
e.Item.Cells[6].Text = member.About;
e.Item.Cells[7].Text = member.ImageURL;
member = null;
break;
}
default:
{
break;
}
}
}
--
Message posted via DotNetMonster.com
[url]http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-datagrid/200511/1[/url]
treilly via DotNetMonster.com Guest
-
LoadViewState does not fire on a postback event
Hi there, I need some help please. I have created a composite control that have a collection of items associated with it. Now I want to save this... -
Checkbox in Datagrid doesn't fire event
I've added a Checkbox control to a Datagrid and would like to Enable/Disable a button based on whether the checkbox is checked. However, I'm trying... -
Bug in _EditCommand, event didn't fire? +my solution
Hello, I had a problem that the _EditCommand didn't fire when the event was created in the .vb code. I did like this: 1. I created a datagrid... -
how to fire a postback event
Hi, All I design a composite custom control, which has three dropdownlists in it. I find as long as one of the dropdownlist control's id is... -
fire button event programmatically
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a... -
Sylvain Lafontaine #2
Re: Takes two clicks to fire event?? Please help!
I don't know about your problem (didn't make any test) but a possible
solution would be to use two buttons and hide/unhide the buttons as
required.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: [url]http://cerbermail.com/?QugbLEWINF[/url]
"treilly via DotNetMonster.com" <u15154@uwe> wrote in message
news:580b49440aebf@uwe...> Hey guys,
>
> This is really starting to annoy me. In short, I have a datagrid with a
> buttoncolumn in the first column. Once a user clicks on a button in this
> column, it fires the OnItemCommand correctly. In the OnItemCommand
> function,
> I then replace the control that fired with a different one in order to
> perform some other actions the next time it is clicked. Everything works
> as
> expected, except it takes two clicks in order to fire the events which
> totally screws up my datagrid.
>
> After doing some research on this problem, I THINK I may need to add the
> RaiseBubbleEvent and OnBubbleEvent functions to my code. The only problem
> is,
> I've tried doing that with no success. Perhaps I am doing it incorrectly.
> Can anyone shed some light on where I may need to add the RaiseBubbleEvent
> (this, e) line as well as where to place my OnBubbleEvent function?
>
> I can't think of any other reason why it would take two clicks to fire the
> event.
> I wanted to post this question without including code because I know how
> terrible it is looking through somebody else's code - but I don't think I
> could have done it without confusing myself as well as others.
> Thanks for the help in advance!
>
> -TR
>
> Here is my code for the OnItemCommand handler:
>
> protected void ItemClick(Object source, DataGridCommandEventArgs e)
> {
>
> switch (e.CommandName) //depending on which button the user
> clicked
> {
> case "cmdArrow": //expand the item to show more info,
> picture
> {
>
> LinkButton downArrow = new LinkButton();
> //replace
> the old control with the new control
> downArrow.ID = "downArrow";
> downArrow =
> (LinkButton)e.Item.Cells[0].Controls[0];
> downArrow.Text = "<img src='arrowdownVA.GIF'
> border='0'/>";
> downArrow.CommandName = "downArrow";
>
>
> string name; //temporary storage variables
> string title;
> string location;
> string phone;
> string emladdress;
> string email;
> string about;
> string imageURLwithTag;
> string imageURL;
>
> LinkButton linkBtn = (LinkButton)e.Item.Cells[1].
> Controls[0];
> name = linkBtn.Text;
> title = e.Item.Cells[2].Text;
> location = e.Item.Cells[3].Text;
> phone = e.Item.Cells[4].Text;
> HyperLink hyperLnk = (HyperLink)e.Item.Cells[5].
> Controls[0];
> emladdress = hyperLnk.Text;
> email = "<a href='mailto:" + emladdress + "'>" +
> emladdress.ToLowerInvariant() + "</a>";
> about = e.Item.Cells[6].Text;
> imageURLwithTag = "<img src=" +
> e.Item.Cells[7].Text
> + "/>"; //width='100px' height='80px'
> imageURL = e.Item.Cells[7].Text;
>
> TableCellCollection tcc = e.Item.Cells; //clear all
> but the first column's controls
> int totalCols = tcc.Count;
> for (int i = 1; i < totalCols - 1; i++)
> {
> e.Item.Cells.RemoveAt(0);
>
> }
>
> e.Item.Cells[0].Controls.Add(downArrow); //add
> the
> new control to first column of datagrid
>
> e.Item.Cells[1].ColumnSpan = 5; //column needs
> to
> span 5 in order to show more info
> e.Item.Cells[1].Text = "<div class='imageHolder'>"
> +
> imageURLwithTag + "</div>";
> e.Item.Cells[1].Text += "<div
> class='infoBlock'><div
> class='expandedName'>" + name + "</div><br/>"
> + "<div class='expandedTitle'>" + title +
> "</div><br/>"
> + "<div class='expandedLocation'>" + location +
> "</div><br/>"
> + "<div class='expandedPhone'>" + phone +
> "</div><br/>"
> + "<div class='expandedEmail'>" + email +
> "</div></div>"; ;
> e.Item.Cells[1].Text += "<div
> class='expandedAbout'>"
> + about + "</div>";
>
> //save this row in sessionstate
> dirMember member = new dirMember(name, title,
> location, phone, emladdress, about, imageURL);
> Session[e.Item.ItemIndex.ToString()] = member;
>
>
> break;
> }
> case "downArrow":
> {
> LinkButton cmdArrow = new LinkButton(); //replace
> the
> old control with the new control
> cmdArrow.ID = "cmdArrow";
> cmdArrow = (LinkButton)e.Item.Cells[0].Controls[0];
> cmdArrow.Text = "<img src='arrowVA.gif' border='0'/>";
> cmdArrow.CommandName = "cmdArrow";
>
> TableCellCollection tcc = e.Item.Cells; //clear all but
> the first column's controls
> int totalCols = tcc.Count;
> for (int i = 1; i < totalCols - 1; i++)
> {
> e.Item.Cells.RemoveAt(0);
>
> }
>
> e.Item.Cells[0].Controls.Add(cmdArrow); //add the
> control to first column of datagrid
>
> //restore member's info to original columns
> dirMember member = (dirMember)Session[e.Item.ItemIndex.
> ToString()];
>
> for(int i = 1; i < DataGrid1.Columns.Count - 1; i++)
> //return columns to original spans
> {
> TableCell tc = new TableCell();
> tc.ColumnSpan = 1;
> e.Item.Cells.AddAt(i, tc);
> }
>
> LinkButton collapsedName = new LinkButton();
> collapsedName.CommandName = "cmdArrow";
> collapsedName.Text = member.Name;
> e.Item.Cells[1].Controls.Add(collapsedName);
>
> e.Item.Cells[2].Text = member.Title; //place the
> info
> from session state back into columns
> e.Item.Cells[3].Text = member.Location;
> e.Item.Cells[4].Text = member.Phone;
> LinkButton collapsedEml = new LinkButton();
> collapsedEml.Text = "<a href='mailto:" + member.
> Emladdress + "'>" + member.Emladdress + "</a>";
> e.Item.Cells[5].Controls.Add(collapsedEml);
> e.Item.Cells[6].Text = member.About;
> e.Item.Cells[7].Text = member.ImageURL;
>
> member = null;
>
> break;
> }
>
> default:
> {
> break;
> }
>
> }
>
> }
>
> --
> Message posted via DotNetMonster.com
> [url]http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-datagrid/200511/1[/url]
Sylvain Lafontaine Guest



Reply With Quote

