commandfield question

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

I have a gridview that has a commandfield in it at the start of each row.
Here is the commandfield.

<asp:CommandField SelectText="Detail" ShowSelectButton="true"
ButtonType="Link" />

I need to open a webform in another window from this and pass a parameter of
the ID for the record in the selected row. Preference would be to have this
occur on the client side. How would this be accomplished? Samples/examples
links are welcomed.

Thanks...John
 
I have a gridview that has a commandfield in it at the start of each row.
Here is the commandfield.

<asp:CommandField SelectText="Detail" ShowSelectButton="true"
ButtonType="Link" />

I need to open a webform in another window from this and pass a parameter
of
the ID for the record in the selected row. Preference would be to have
this
occur on the client side. How would this be accomplished?
Samples/examples
links are welcomed.

Firstly, I wouldn't use a separate column for this - all that does is waste
space on the screen. Instead, I'd wire up a click event on the GridView
itself so that all the users have to do is click the row:

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style["cursor"] = "pointer";
/* or, if you want only certain cells within
each row to respond to the click event
for (int intCell = 1; intCell < 4; intCell++)
{
e.Row.Cells[intCell].Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Cells[intCell].Style["cursor"] = "pointer";
}
*/
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
// do something with MyGridView.SelectedValue.ToString();
}


Secondly, I absolutely would not do anything which opens another window. For
one thing, depending on how the rest of the application is written and
deployed, and what browser the users are using, this is likely to trigger
the popup blocker. Also, there has been instances of the child window losing
contact with the main window's Session or, in some cases, even creating a
new Session. Instead, I'd use the AJAX modal popup extender:
http://www.google.co.uk/search?aq=0&oq=AJAX+moda&sourceid=chrome&ie=UTF-8&q=ajax+modal+popup

That would mean that you wouldn't need to pass anything anywhere, as the
modal popup would have access to the entire page anyway, so anything it
needed to know it could simply look up...
 
Mark Rae said:
I have a gridview that has a commandfield in it at the start of each row.
Here is the commandfield.

<asp:CommandField SelectText="Detail" ShowSelectButton="true"
ButtonType="Link" />

I need to open a webform in another window from this and pass a parameter
of
the ID for the record in the selected row. Preference would be to have
this
occur on the client side. How would this be accomplished?
Samples/examples
links are welcomed.

Firstly, I wouldn't use a separate column for this - all that does is waste
space on the screen. Instead, I'd wire up a click event on the GridView
itself so that all the users have to do is click the row:

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style["cursor"] = "pointer";
/* or, if you want only certain cells within
each row to respond to the click event
for (int intCell = 1; intCell < 4; intCell++)
{
e.Row.Cells[intCell].Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Cells[intCell].Style["cursor"] = "pointer";
}
*/
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
// do something with MyGridView.SelectedValue.ToString();
}


Secondly, I absolutely would not do anything which opens another window. For
one thing, depending on how the rest of the application is written and
deployed, and what browser the users are using, this is likely to trigger
the popup blocker. Also, there has been instances of the child window losing
contact with the main window's Session or, in some cases, even creating a
new Session. Instead, I'd use the AJAX modal popup extender:
http://www.google.co.uk/search?aq=0&oq=AJAX+moda&sourceid=chrome&ie=UTF-8&q=ajax+modal+popup

That would mean that you wouldn't need to pass anything anywhere, as the
modal popup would have access to the entire page anyway, so anything it
needed to know it could simply look up...

Thanks for the info. The modal pop extender should work for the users and
enact some type of response from them. Unfortunately, the commandfield has
to be there for the users. The 'has to be there' was emphasized early on.
Does that now change what your response from what was provided above?
.... John
 
Thanks for the info. The modal pop extender should work for the users and
enact some type of response from them.
Excellent.


Unfortunately, the commandfield has to be there for the users. The 'has
to be there'
was emphasized early on.

By whom? Does the Mighty Emphasizer even realise that the commandfield is
completely unnecessary...?

Does that now change what your response from what was provided above?

Only that you'll have to wire up the commandfield to pop the modal popup
rather than the GridView's SelectedIndexChanged event. Other than that,
there's no difference...
 
Mark Rae said:
By whom? Does the Mighty Emphasizer even realise that the commandfield is
completely unnecessary...?



Only that you'll have to wire up the commandfield to pop the modal popup
rather than the GridView's SelectedIndexChanged event. Other than that,
there's no difference...

The 'Mighty Emphasizer' is alot further up the food chain than I am. He
will get these ideas that can be impossible to change. Plus, he is thinking
of the saying, 'out of site, out of mind' and staffers will forget about the
row click. Especially new staff and temps.

I am really liking the modal idea. I've seen users (many) on what is used
now open a screen, decide not to do anything, minimize it and forget it or
just open another screen and leave the other open.

Thanks.
 
The 'Mighty Emphasizer' is a lot further up the food chain than I am. He
will get these ideas that can be impossible to change.

I've encountered the type many, many times before - you have my sympathy...

Plus, he is thinking of the saying, 'out of sight, out of mind' and
staffers will forget
about the row click. Especially new staff and temps.

Trust me, they don't. I've used this functionality on dozens (maybe hundreds
by now) of client apps and no-one has a problem with is. Especially since
the cursor changes to a pointer when the user moves over the grid, which
tells them "click me" because that's what they're used to...

Why not implement it anyway...? He might start liking it himself!

I am really liking the modal idea. I've seen users (many) on what is used
now open a screen, decide not to do anything, minimize it and forget it or
just open another screen and leave the other open.

Yes indeed. Opening multiple browsers windows is extremely "vieux chapeau"
these days...
 
Mark Rae said:
I've encountered the type many, many times before - you have my sympathy...



Trust me, they don't. I've used this functionality on dozens (maybe hundreds
by now) of client apps and no-one has a problem with is. Especially since
the cursor changes to a pointer when the user moves over the grid, which
tells them "click me" because that's what they're used to...

Why not implement it anyway...? He might start liking it himself!



Yes indeed. Opening multiple browsers windows is extremely "vieux chapeau"
these days...

I just might go without the command field and implement your suggestion and
see if he notices. Who knows maybe 'out of site, out of mind' could come
into play.
Thanks.
 
JohnE said:
I just might go without the command field and implement your suggestion and
see if he notices. Who knows maybe 'out of site, out of mind' could come
into play.
Thanks.

I just realized that I have a nested gridview in the main gridview. This
might change what is used. The RowDataBound is used for the nested gridview.
Another must have item from the Mighty Emphasizer. One which he will
remember.
 
Mark Rae said:
Good idea! I've done that many times in the past - 9 times out of 10 they
don't notice...



Indeed.

BTW, "site" = location, "sight" = vision:
http://www.phrases.org.uk/meanings/274400.html

Here's a thought, what if I remove the <asp:CommandField totally. In place
of ID field on the gridview (<asp:BoundField) I use an <asp:ButtonField with
type set to link, datatextfield to the ID, headertext to ID, and
sortexpression to ID? I gain space back and show the ID as a link for the
user (which they are familiar with). Will need to highlight the row when
selected and work the modalpopupextender for the details of the record (not
just what is in the row).

Will this work? If so, will need a push start for the highlight and modal.
Links if you know of any.

Always open to suggestions and other thoughts as well.

Thanks...John
 
Here's a thought, what if I remove the <asp:CommandField totally. In
place
of ID field on the gridview (<asp:BoundField) I use an <asp:ButtonField
with
type set to link, datatextfield to the ID, headertext to ID, and
sortexpression to ID? I gain space back

Hmm - how do you actually gain space? You're just replacing one unnecessary
column with another unnecessary column...

Will this work?

I would think so.

If so, will need a push start for the highlight and modal.

Assuming the whole thing is inside an AJAX UpdatePanel, you would just need
to wire up the ButtonField's OnClick event to show the modal popup...
 
Mark Rae said:
Hmm - how do you actually gain space? You're just replacing one unnecessary
column with another unnecessary column...



I would think so.



Assuming the whole thing is inside an AJAX UpdatePanel, you would just need
to wire up the ButtonField's OnClick event to show the modal popup...

Space gained from the column that had the asp:commandfield in it is gone.
The ID column is already there which is now replaced with an asp:buttonfield.
I did the replacing and so far the gridview is still functioning, with one
less column. The gridview is not inside an updatepanel. Tried that some
time ago and it scramble the calender extender I have on a date field when
the Edit is used. Other wise the update panel would be nice.

The panel aside, how would I get the row to highlight like when the
commandfield was used? Had the following code that was used with the
commandfield.

protected void gvwChangeRequestList_SelectedIndexChanging(object sender,
GridViewSelectEventArgs e)
{
if (gvwChangeRequestList.SelectedIndex == e.NewSelectedIndex)
{
e.Cancel = true;
gvwChangeRequestList.SelectedIndex = -1;
}
//Response.Redirect("place the Detail page info here");
}

But now no row highlight when the buttonfield is used.

Thanks for stickin' around for this.

John
 
Space gained from the column that had the asp:commandfield in it is gone.
The ID column is already there which is now replaced with an
asp:buttonfield.

Ah, right - understood.

I did the replacing and so far the gridview is still functioning, with one
less column. The gridview is not inside an updatepanel. Tried that some
time ago and it scrambles the calender extender I have on a date field
when
the Edit is used. Other wise the update panel would be nice.

Hmm - well, you're going to need the update panel in order to use the modal
popup - no way round that...

The panel aside, how would I get the row to highlight like when the
commandfield was used?

Not why you're trying to get the row to highlight, but I'd imagine you'd
need to set its background colour at the top of the SelectedIndexChanging
method...
 
Mark Rae said:
Ah, right - understood.



Hmm - well, you're going to need the update panel in order to use the modal
popup - no way round that...



Not why you're trying to get the row to highlight, but I'd imagine you'd
need to set its background colour at the top of the SelectedIndexChanging
method...

Here is the calendarextender that I'm using along with the css. How do I
keep it from getting scrambled inside the updatepanel? Which is why I
abandoned the updpanel. I would need to solve that before moving on to the
buttonfield, command, etc.

<asp:TemplateField HeaderText="Target End Date"
SortExpression="DevTargetEndDate">
<ItemTemplate>
<asp:Label ID="lblDevTargetEndDate" runat="server"
Text='<%# Bind("DevTargetEndDate", "{0:M-d-yyyy}") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDevTargetEndDate" runat="server"
Text='<%# Bind("DevTargetEndDate", "{0:M-d-yyyy}") %>'></asp:TextBox>
<cc1:CalendarExtender ID="calDevTargetEndDate"
runat="server" TargetControlID="txtDevTargetEndDate"
Format="M/d/yyyy" CssClass="ListEdit_theme1" >
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>

-----

..ListEdit_theme1 .ajax__calendar_container
{
border:1px solid Black;
background-color: Aqua;
}

..ListEdit_theme1 .ajax__calendar_header
{
background-color: White;
margin-bottom: 4px;
}

..ListEdit_theme1 .ajax__calendar_title,
..ListEdit_theme1 .ajax__calendar_next,
..ListEdit_theme1 .ajax__calendar_prev
{
color: Blue;
padding-top: 3px;
}

..ListEdit_theme1 .ajax__calendar_body
{
background-color: White;
border: solid 1px #cccccc;
}

..ListEdit_theme1 .ajax__calendar_dayname
{
text-align: center;
font-weight: bold;
margin-bottom: 4px;
margin-top: 2px;
}
..ListEdit_theme1 .ajax__calendar_active
{
color: Red;
background-color: White;
font-weight: bold;
}

..ListEdit_theme1 .ajax__calendar_hover .ajax__calendar_day,
..ListEdit_theme1 .ajax__calendar_hover .ajax__calendar_month,
..ListEdit_theme1 .ajax__calendar_hover .ajax__calendar_year
{
color: Red;
background-color: Yellow;
font-weight: bold;
}

..ListEdit_theme1 .ajax__calendar_today
{
font-weight: bold;
}

..ListEdit_theme1 .ajax__calendar_hover .ajax__calendar_today
{
background-color: Red;
}

..ListEdit_theme1 .ajax__calendar_other,
..ListEdit_theme1 .ajax__calendar_hover .ajax__calendar_day,
..ListEdit_theme1 .ajax__calendar_hover .ajax__calendar_title
{
color: Maroon;
}

Thanks.
 
Here is the calendarextender that I'm using along with the css. How do I
keep it from getting scrambled inside the updatepanel?

Looks OK to me. Maybe something else in the page / application is causing
the problem...?

There's a very simple example of using a Calendar control in an UpdatePanel
here:
http://msdn.microsoft.com/en-us/library/bb399001.aspx

If you have the time and/or the inclination, you might like to try the
examples in the above webpage on a new aspx page page in your app and see if
the calendar works. Assuming it does, then try adding the CSS to it bit by
bit - I'm betting that's what the problem is...
 
Back
Top