By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,208 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,208 IT Pros & Developers. It's quick & easy.

Datagrid 'select' button oddities

P: n/a
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="TableCellAlternatin g"/>
<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

Mar 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Mar 20 '06 #2

P: n/a
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

P: n/a
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
Mar 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.