Datagrid 'select' button oddities

G

Guest

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
understand

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="TableCellAlternating"/>
<ItemStyle CssClass="TableCellNormal"/>
<HeaderStyle CssClass="TableHeader" />
<SelectedItemStyle BackColor=#999999 />



<!-- columns start here -->
<Columns>
<asp:ButtonColumn runat="server" Text="Select" CommandName="Select"/>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Edit Data" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="RD File Number">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "rd_file_no") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtRdfileno" Runat="server" Text='
<%# DataBinder.Eval(Container.DataItem,"rd_file_no") %>' />
</EditItemTemplate>
</asp:TemplateColumn>


<!-- 2 more columns with exactly the same markup but pointing to differnt
fields -->

</columns>
</datagrid>



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
built-in

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...

but...

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,
CharlesA
 
J

Joey

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

JP
 
G

Guest

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.
 
G

Guest

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
Regards,
CharlesA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top