471,594 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Datagrid 'select' button oddities

Hi folks,
I really need help with the following scenario,
I'm going to describe as well as a I can what the setup is and what I can't

I'm using the framework 1.1 using ASP.net with C#

I have a datagrid that is bound to a datasource (through ADO.net) and all
that works

I haven't autogenerated the columns and I haven't used the <asp:boundcolumn
markup either

instead I have three columns preceded by two buttons and this kind of markup

<!-- Datagrid declaration -->

<asp:datagrid id="dgRDs" runat="server"
AutoGenerateColumns="False" CssClass="DataGridClass">

<AlternatingItemStyleCssClass="TableCellAlternatin g"/>
<ItemStyle CssClass="TableCellNormal"/>
<HeaderStyle CssClass="TableHeader" />
<SelectedItemStyle BackColor=#999999 />

<!-- columns start here -->
<asp:ButtonColumn runat="server" Text="Select" CommandName="Select"/>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Edit Data" CancelText="Cancel"
<asp:TemplateColumn HeaderText="RD File Number">
<%# DataBinder.Eval(Container.DataItem, "rd_file_no") %>
<asp:TextBox ID="txtRdfileno" Runat="server" Text='
<%# DataBinder.Eval(Container.DataItem,"rd_file_no") %>' />
<!-- 2 more columns with exactly the same markup but pointing to differnt
fields -->


As you can see I have two Template columns per column
1 to give the unedited look and one to add a textbox (with an id) for the
edited row look
here's what I'm mystified about

I have a 'Select' Button column and Dino Esposito in his magnum opus says:
There is no need to write an ItemCommand handler, the described behavior is

i.e when you click the Select hyperlink whatever style you chose becomes the
background of the row

and indeed he's right and it does do that...


it also puts the row into Edit mode even though I'm not choosing the Edit
hyperlink (which does have an event handler)

This is my question.
how can I select a row without also placing it in Edit mode

I went with the <asp:TemplateColumn> route because I wanted to be able to
used named text boxes, when I do an update, and not just have the Datagrid
control give a whole load of meaningless autogenerated names
if you can help me with my select Question, I'd greatly appreciate it

Regards and thanks in advance,

Mar 20 '06 #1
3 1543
Do your thing in the event handler and then at the bottom of the code
block set the grid's SelectedItemIndex property to -1.


Mar 20 '06 #2
It's OK, I got it,
I realized that I hadn't done my

if (e.commandName == "Edit")
in the ItemCommand event handler of the grid

all is fine now.
Mar 20 '06 #3
thanks Joey
I thought I had replied to my own original post...but it appears my reply is
not there
I figured it out.... I was doing a

switch case in the grid's ItemCommand event handler and I just needed to
wrap up the code that was used for editing inside
Case commandname== "Edit" and isolate it so that when select calls the event
handler it doesn't go into Edit mode

all is well and thanks anyway for your help
Mar 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Daniel Walzenbach | last post: by
2 posts views Thread by Bob Hollness | last post: by
5 posts views Thread by Vik | last post: by
1 post views Thread by Brock | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

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.