473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Template Column, EditCommandColumn issues

Ron
Hello,
I am trying to create a page that pulls class rosters from an SQLServer
database. The roster table definition is: emp_id(pk, fk), sec_id(pk, fk),
reg_date and reg_status. Status can be Pending, Cancelled or NoShow. I want
the page to display section information (working fine) as well as a datagrid
of all the employees and their status'. Status should be displayed in a
dropdownlist control and is the only control you can edit.

Help:
1) When the datagrid loads, all columns load fine except the dropdownlist
column, which just show the header and blank cells underneath. I obvioussly
need the ddl to show at all times, including before you click edit. Dropdown
code follows:
---
<asp:DataGrid ID="secRoster" runat="server" AutoGenerateColumns="false"
showHeader="true" CellPadding="5" OnCancelCommand="CancelEdit"
OnEditCommand="EditRecord" OnUpdateCommand="updaterecordedit">
<columns>
<asp:Boundcolumn datafield="emp_id" visible="false"/>
<asp:Boundcolumn datafield="sec_id" visible="false"/>
....more columns working as expected...
<asp:TemplateColumn HeaderText="Status">
<EditItemTemplate>
<asp:DropDownList ID="ddlregstatus" runat="server">
<asp:ListItem Value="Pending" Text="Pending"/>
<asp:ListItem Value="Cancelled" Text="Cancelled"/>
<asp:ListItem Value="Noshow" Text="No Show"/>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit" ItemStyle-Font-Size="smaller"
ItemStyle-Width="10%"/>
</columns>
---

2) When you click Edit the ddl shows with the default value selected. It
should obviously reflect whats in the DB. The following is the load grid
code. I am pretty sure I am missing somthing:
---
Private sub load_grid()
dim strsql as string = "SELECT * FROM roster_info WHERE sec_id = " &
ddlSec.selecteditem.value
Connect()
dim adapter as New SqlDataAdapter(strSQL, objconnection)
dim ds as New DataSet()
adapter.Fill(ds, "Roster")
Disconnect()
secroster.datasource = ds.tables("Roster")
secroster.databind()
end sub
---
3) Finally, at least for now, when I attempt to update a row, I get a
problem that is seemingly unrelated to the ddl. I get this error:
"System.FormatException: Input string was not in a correct format."
The edit column uses the following code:
---
Public Sub EditRecord(ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
secroster.edititemIndex = E.Item.ItemIndex
Load_Grid()
end sub

Public Sub CancelEdit (ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
secroster.edititemindex = -1
Load_Grid()
End sub

Public Sub UpdateRecordEdit (ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
dim empid as int32 = convert.toint32(e.item.cells(0).text) <-----This is
the line causing the error.
dim secid as int32 = convert.toint32(e.item.cells(1).text)
Dim TempList As DropDownList
TempList = E.Item.FindControl("ddlregstatus")
dim regstatus as string = templist.selecteditem.value
secroster.edititemindex = -1
UpdateRoster(empid, secid, regstatus)
End sub

Private Sub UpdateRoster (ByVal empid as integer, byval secid as integer,
byval editstatus as string)
dim strsql as string = "SELECT * FROM roster_info WHERE sec_id = " & secid
Connect()
dim adapter as New SqlDataAdapter(strsql, objconnection)
dim ds as new dataset()
adapter.fill(ds, "Roster")
disconnect()

dim tbl as datatable = ds.tables("Roster")
tbl.primarykey = New DataColumn() _
{ _
tbl.Columns("EmpID"), _
tbl.Columns("SecID") _
}
dim row as datarow = tbl.rows.find(empid)
row.item("reg_status") = editstatus

dim cb as new sqlcommandbuilder(adapter)
Connect()
adapter.update(ds, "Roster")
disconnect()
End sub
---

I hope I gave enough information to properly convey my issue(s), w/o
overwhelming anyone. I really appreciate any help at all. Thanks for reading
my book...

--Ron
Nov 18 '05 #1
2 1648
Ron
Ok, I figured out the solution to problems 1 & 2:

Add:
---
<ItemTemplate>
<%#Container.DataItem("reg_status")%>
</ItemTemplate>
---
to the template column. I am still seeking assistance for issue 3 however.
Thanks in advance.

--Ron
"Ron" wrote:
Hello,
I am trying to create a page that pulls class rosters from an SQLServer
database. The roster table definition is: emp_id(pk, fk), sec_id(pk, fk),
reg_date and reg_status. Status can be Pending, Cancelled or NoShow. I want
the page to display section information (working fine) as well as a datagrid
of all the employees and their status'. Status should be displayed in a
dropdownlist control and is the only control you can edit.

Help:
1) When the datagrid loads, all columns load fine except the dropdownlist
column, which just show the header and blank cells underneath. I obvioussly
need the ddl to show at all times, including before you click edit. Dropdown
code follows:
---
<asp:DataGrid ID="secRoster" runat="server" AutoGenerateColumns="false"
showHeader="true" CellPadding="5" OnCancelCommand="CancelEdit"
OnEditCommand="EditRecord" OnUpdateCommand="updaterecordedit">
<columns>
<asp:Boundcolumn datafield="emp_id" visible="false"/>
<asp:Boundcolumn datafield="sec_id" visible="false"/>
...more columns working as expected...
<asp:TemplateColumn HeaderText="Status">
<EditItemTemplate>
<asp:DropDownList ID="ddlregstatus" runat="server">
<asp:ListItem Value="Pending" Text="Pending"/>
<asp:ListItem Value="Cancelled" Text="Cancelled"/>
<asp:ListItem Value="Noshow" Text="No Show"/>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit" ItemStyle-Font-Size="smaller"
ItemStyle-Width="10%"/>
</columns>
---

2) When you click Edit the ddl shows with the default value selected. It
should obviously reflect whats in the DB. The following is the load grid
code. I am pretty sure I am missing somthing:
---
Private sub load_grid()
dim strsql as string = "SELECT * FROM roster_info WHERE sec_id = " &
ddlSec.selecteditem.value
Connect()
dim adapter as New SqlDataAdapter(strSQL, objconnection)
dim ds as New DataSet()
adapter.Fill(ds, "Roster")
Disconnect()
secroster.datasource = ds.tables("Roster")
secroster.databind()
end sub
---
3) Finally, at least for now, when I attempt to update a row, I get a
problem that is seemingly unrelated to the ddl. I get this error:
"System.FormatException: Input string was not in a correct format."
The edit column uses the following code:
---
Public Sub EditRecord(ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
secroster.edititemIndex = E.Item.ItemIndex
Load_Grid()
end sub

Public Sub CancelEdit (ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
secroster.edititemindex = -1
Load_Grid()
End sub

Public Sub UpdateRecordEdit (ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
dim empid as int32 = convert.toint32(e.item.cells(0).text) <-----This is
the line causing the error.
dim secid as int32 = convert.toint32(e.item.cells(1).text)
Dim TempList As DropDownList
TempList = E.Item.FindControl("ddlregstatus")
dim regstatus as string = templist.selecteditem.value
secroster.edititemindex = -1
UpdateRoster(empid, secid, regstatus)
End sub

Private Sub UpdateRoster (ByVal empid as integer, byval secid as integer,
byval editstatus as string)
dim strsql as string = "SELECT * FROM roster_info WHERE sec_id = " & secid
Connect()
dim adapter as New SqlDataAdapter(strsql, objconnection)
dim ds as new dataset()
adapter.fill(ds, "Roster")
disconnect()

dim tbl as datatable = ds.tables("Roster")
tbl.primarykey = New DataColumn() _
{ _
tbl.Columns("EmpID"), _
tbl.Columns("SecID") _
}
dim row as datarow = tbl.rows.find(empid)
row.item("reg_status") = editstatus

dim cb as new sqlcommandbuilder(adapter)
Connect()
adapter.update(ds, "Roster")
disconnect()
End sub
---

I hope I gave enough information to properly convey my issue(s), w/o
overwhelming anyone. I really appreciate any help at all. Thanks for reading
my book...

--Ron

Nov 18 '05 #2
Ron
Well, I finally figured it out. I used parameters to go into the DB and it
worked.
The following replaced UpdateRoster and UpdateRecordEdit in my original
post. Thanks for all the quick responses!
---
Private Sub UpdateRoster (ByVal source As Object, ByVal e As
DataGridCommandEventArgs)
Dim DDL As DropDownList = CType(e.Item.Cells(5).Controls(1), DropDownList)
Dim NewStat As String = DDL.SelectedValue
dim empid as int32 = Int32.Parse(e.Item.Cells(0).Text)
dim secid as int32 = Int32.Parse(e.Item.Cells(1).Text)
dim strsql as string = "UPDATE rosters SET reg_status = @status " & _
"WHERE emp_id = @empid1 and sec_id = @secid1"
Dim Cmd As New SqlCommand(strsql, objconnection)
Cmd.Parameters.Add(New SqlParameter("@empid1", empid))
Cmd.Parameters.Add(New SqlParameter("@secid1", secid))
Cmd.Parameters.Add(New SqlParameter("@status", newstat))
Connect()
cmd.executenonquery()
disconnect()
secroster.EditItemIndex = -1
Load_Grid()
End sub
---

"Ron" wrote:
Ok, I figured out the solution to problems 1 & 2:

Add:
---
<ItemTemplate>
<%#Container.DataItem("reg_status")%>
</ItemTemplate>
---
to the template column. I am still seeking assistance for issue 3 however.
Thanks in advance.

--Ron
"Ron" wrote:
Hello,
I am trying to create a page that pulls class rosters from an SQLServer
database. The roster table definition is: emp_id(pk, fk), sec_id(pk, fk),
reg_date and reg_status. Status can be Pending, Cancelled or NoShow. I want
the page to display section information (working fine) as well as a datagrid
of all the employees and their status'. Status should be displayed in a
dropdownlist control and is the only control you can edit.

Help:
1) When the datagrid loads, all columns load fine except the dropdownlist
column, which just show the header and blank cells underneath. I obvioussly
need the ddl to show at all times, including before you click edit. Dropdown
code follows:
---
<asp:DataGrid ID="secRoster" runat="server" AutoGenerateColumns="false"
showHeader="true" CellPadding="5" OnCancelCommand="CancelEdit"
OnEditCommand="EditRecord" OnUpdateCommand="updaterecordedit">
<columns>
<asp:Boundcolumn datafield="emp_id" visible="false"/>
<asp:Boundcolumn datafield="sec_id" visible="false"/>
...more columns working as expected...
<asp:TemplateColumn HeaderText="Status">
<EditItemTemplate>
<asp:DropDownList ID="ddlregstatus" runat="server">
<asp:ListItem Value="Pending" Text="Pending"/>
<asp:ListItem Value="Cancelled" Text="Cancelled"/>
<asp:ListItem Value="Noshow" Text="No Show"/>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit" ItemStyle-Font-Size="smaller"
ItemStyle-Width="10%"/>
</columns>
---

2) When you click Edit the ddl shows with the default value selected. It
should obviously reflect whats in the DB. The following is the load grid
code. I am pretty sure I am missing somthing:
---
Private sub load_grid()
dim strsql as string = "SELECT * FROM roster_info WHERE sec_id = " &
ddlSec.selecteditem.value
Connect()
dim adapter as New SqlDataAdapter(strSQL, objconnection)
dim ds as New DataSet()
adapter.Fill(ds, "Roster")
Disconnect()
secroster.datasource = ds.tables("Roster")
secroster.databind()
end sub
---
3) Finally, at least for now, when I attempt to update a row, I get a
problem that is seemingly unrelated to the ddl. I get this error:
"System.FormatException: Input string was not in a correct format."
The edit column uses the following code:
---
Public Sub EditRecord(ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
secroster.edititemIndex = E.Item.ItemIndex
Load_Grid()
end sub

Public Sub CancelEdit (ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
secroster.edititemindex = -1
Load_Grid()
End sub

Public Sub UpdateRecordEdit (ByVal Sender as Object, ByVal E as
DataGridCommandEventArgs)
dim empid as int32 = convert.toint32(e.item.cells(0).text) <-----This is
the line causing the error.
dim secid as int32 = convert.toint32(e.item.cells(1).text)
Dim TempList As DropDownList
TempList = E.Item.FindControl("ddlregstatus")
dim regstatus as string = templist.selecteditem.value
secroster.edititemindex = -1
UpdateRoster(empid, secid, regstatus)
End sub

Private Sub UpdateRoster (ByVal empid as integer, byval secid as integer,
byval editstatus as string)
dim strsql as string = "SELECT * FROM roster_info WHERE sec_id = " & secid
Connect()
dim adapter as New SqlDataAdapter(strsql, objconnection)
dim ds as new dataset()
adapter.fill(ds, "Roster")
disconnect()

dim tbl as datatable = ds.tables("Roster")
tbl.primarykey = New DataColumn() _
{ _
tbl.Columns("EmpID"), _
tbl.Columns("SecID") _
}
dim row as datarow = tbl.rows.find(empid)
row.item("reg_status") = editstatus

dim cb as new sqlcommandbuilder(adapter)
Connect()
adapter.update(ds, "Roster")
disconnect()
End sub
---

I hope I gave enough information to properly convey my issue(s), w/o
overwhelming anyone. I really appreciate any help at all. Thanks for reading
my book...

--Ron

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article:...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
0
by: me | last post by:
If i add an edit column dynamicly: EditCommandColumn edcol = new EditCommandColumn(); edcol.ButtonType = ButtonColumnType.LinkButton; linksDataGrid.Columns.AddAt(0,edcol); then when i press...
4
by: starwiz | last post by:
I'm trying to use the DataGrid's editing with a DropDownList. I've tried using every code sample I've seen and none of them seem to be able to solve my problem. When I call...
0
by: tshad | last post by:
I have a table which works fine using the following templates: ********************************************************************************** <asp:TemplateColumn HeaderText="Answer">...
1
by: tshad | last post by:
I have a row like this that works fine: *************************************************************** <asp:DataGrid visible="False" border=1 id="DataGrid1" runat="server" Width="400px"...
3
by: John E. | last post by:
I have a datatable that I am binding to a C# ASP.NET 1.1 web page datagrid. I also want to put an "Edit" column on the datagrid. However, whenever I use the following code, it puts the Edit...
1
by: Mike C | last post by:
I'm new to Web development so I'm doing some bootstrapping and would really appreciate any help. Been grappling with this for days and am utterly confused by all the information on the web. I have...
0
by: nicolass | last post by:
Hi, Im new in c# :) I wonder how to change color of some cell if there is some criteria. ie. if value in cell = John then color of that cell is Red This very easy in PHP but c#.. :(
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.