?
Solved

Dreamweaver / ASP.NET inserting an EDIT button into a datagrid

Posted on 2007-07-28
4
Medium Priority
?
349 Views
Last Modified: 2008-02-07
Hi I am fairly new to Dreamweaver and asp.net so any help and guidance will be much appreciated.

I have a datagrid bound to a sql server table, and want to insert an "EDIT" button into the first column of the datagrid for each record. I presume I can do this in the <columns> section of the datagrid definition (I may well be wrong though) with a statement like

<asp:ButtonColumn Text="Edit" Visible="true" ButtonType="linkButton" />

however I have no idea of how to assign a value to the button, so that when it is pressed, I can act accordingly on the selected record.

Any help to point me in the right direction and get me coding again would be very much appreciated.

Thanks
...Steve

----current code-----

<asp:datagrid id="dgHistoricAppts" runat="server"
  runat="server"
  AllowSorting="False"
  AutoGenerateColumns="false"
  CellPadding="3"
  CellSpacing="0"
  PageSize="10"
  ShowFooter="false"
  ShowHeader="true"
  PagerStyle-Mode="NextPrev"
  AllowPaging="true"
  AllowCustomPaging="true"
  OnPageIndexChanged="Historic_Page_Changer"

>      <Columns>
             
------
This is where I need to insert my "EDIT" button
and the line I presume I need to enter something like
<asp:ButtonColumn Text="Edit" Visible="true" ButtonType="linkButton" />
------

        <asp:BoundColumn DataField="Appt_Date_DMY"
        HeaderText="Date"
        ReadOnly="true"
        HeaderStyle-Width="100"
        HeaderStyle-HorizontalAlign="left"
        Visible="True"/>    
         
        <asp:BoundColumn DataField="Start_Time"
        HeaderText="Time"
        ReadOnly="true"
        HeaderStyle-Width="80"
        HeaderStyle-HorizontalAlign="left"
        Visible="True"/>
             
        <asp:BoundColumn DataField="Appt_Name"
        HeaderText="Appt Type"
        ReadOnly="true"
        HeaderStyle-Width="200"
        HeaderStyle-HorizontalAlign="left"
        Visible="True"/>      
       
        <asp:BoundColumn DataField="Staff_Name"
        HeaderText="Staff Name"
        ReadOnly="true"
        HeaderStyle-Width="250"
        HeaderStyle-HorizontalAlign="left"
        Visible="True"/>      
      </Columns>
      </asp:DataGrid>
</p>
0
Comment
Question by:swtiley
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:skiltz
ID: 19586219
Okay so first off, if you are serious about asp.net development then please drop Dreamweaver and switch to visual studio or one of the express editions.  You lose so much from not using visual studio, mainly intilliesense which would help you out immensely with your problem above.

AutoGenerateEditButton="True"
DataKeyNames="PrimaryKey"  <---PK of field in database to change to id of whatever the name of your column is.

You then need to create an update command for the datasource. Similar to what I expect you have for your select statement.




0
 
LVL 1

Author Comment

by:swtiley
ID: 19586246
Hi skiltz, and thanks for the quick response.

I know what you mean about VS2005 vs Dreamweaver, as my usual development tool is VS2005. however I have inherited a whole site that has been developed in DW and for what I need to achieve it is (unfortuantely) still easier to do it in DW.

With regards to the code you provided. where does the AutoGenerateEditButton go, as when I tried to input this, in the datagrid definitions (above the column definitions) it was not recognised.

A similar question for DataKeyNames, if the primary key is multiple fields, how would I enter this and where does it go.

Many thanks again,
Steve
0
 
LVL 7

Accepted Solution

by:
skiltz earned 2000 total points
ID: 19586390
Is this .net 1.1 or 2.0?

in .net 1.1 you can add something like this.

<asp:datagrid...id="dgHistoricAppts"

onEditCommand="editCommand"

/>


<columns>
<asp:editCommandColumn>
EditText = "edit"
updateText = "Update"
CancelText = "Cancel" />
</columns>

Sub editCommand ( s as Object e as DataGridCommandEventArgs)
dgHistoricAppts.EditItemIndex = e.item.ItemIndex
BindDataGrid
end sub
0
 
LVL 1

Author Comment

by:swtiley
ID: 19587035
Thank you Skiltz, your help is appreciated, and this question is resolved.

I have another issue, with the same datagrid not paging, if you have any suggestions that question can be found at

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22726637.html

Many thanks again
...Steve
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question