tatton777
asked on
DetailsView - One specific field is not being noticed on the ItemUpdating event
Here is the detailsView and below that is the code that I'm using to make sure that the fields are ALL being passed noticed on the ItemUpdating event. The final field, "Tech" is not being noticed as part of the DetailsView. I thought maybe it just wasn't picking up the bottom field, so I move the "Tech" field to the top of the DetailsView. Even then, "Tech" was not picked up by my C# code as one of the fields that was about to be updated.
<removed by GranMod>
<%--BEGIN TicketDetailsView and DataSource--%>
<asp:DetailsView ID="TicketDetailsView" runat="server" DataSourceID="DetailSqlDat aSource"
DataKeyNames="Question_Id" AutoGenerateRows="False"
OnItemUpdating="TicketDeta ilsView_It emUpdating "
>
<Fields>
<asp:BoundField DataField="Question_Id" HeaderText="Ticket ID" InsertVisible="False"
SortExpression="Question_I d" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField DataField="DateOpened" HeaderText="Date Opened" SortExpression="Date" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField />
<asp:BoundField DataField="Questioner_Id" HeaderText="From" SortExpression="Questioner _Id" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# Eval("Email") %>'
NavigateUrl='<%# Eval("Email", "mailto:{0}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField DataField="Urgency" HeaderText="Urgency" SortExpression="Urgency" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Status" SortExpression="Status" HeaderStyle-Font-Bold="tru e">
<EditItemTemplate>
<asp:DropDownList ID="StatusAssignDropDownLi st" runat="server" SelectedValue='<%# Bind("Status") %>'>
<asp:ListItem>OPEN</asp:Li stItem>
<asp:ListItem>CLOSED</asp: ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="StatusLabel" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField />
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField DataField="Detail" SortExpression="Detail" />
<asp:BoundField />
<asp:BoundField DataField="Tech_Id" HeaderText="Tech ID" SortExpression="Tech_Id" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="tru e">
<EditItemTemplate>
<asp:DropDownList ID="TechAssignDropDownList " runat="server"
DataSourceID="TechSqlDataS ource"
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%Bind ("Tech") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TechLabel" runat="server" Text='<%# Bind ("Tech") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="DetailSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:4Life_Ma sterConnec tionString %>"
UpdateCommand="UPDATE [sDeskQ] SET [Tech]=@Tech, [Status]=@Status
WHERE ([Question_Id] = @Question_Id)"
SelectCommand="SELECT * FROM [sDeskQ] WHERE ([Question_Id] = @Question_Id)">
<SelectParameters>
<asp:ControlParameter ControlID="TicketsGridView " Name="Question_Id"
PropertyName="SelectedValu e" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="TicketsGridView " Name="Question_Id"
PropertyName="SelectedValu e" Type="Int32" />
<asp:Parameter Name="Status" />
<asp:Parameter Name="Tech" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="TechSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:4Life_Ma sterConnec tionString %>"
SelectCommand="SELECT * FROM [sDeskTch]">
</asp:SqlDataSource>
<%--END TicketDetailsView and DataSource--%>
//======================== ========== ========== ===
// TicketDetailsView_ItemUpda ting()
//======================== ========== ========== ===
protected void TicketDetailsView_ItemUpda ting(objec t sender, DetailsViewUpdateEventArgs e)
{
foreach (string key in e.NewValues.Keys)
{
Response.Write("<br>" + key + " " + e.NewValues[key]);
}
e.Cancel = true;
}
<removed by GranMod>
<%--BEGIN TicketDetailsView and DataSource--%>
<asp:DetailsView ID="TicketDetailsView" runat="server" DataSourceID="DetailSqlDat
DataKeyNames="Question_Id"
OnItemUpdating="TicketDeta
>
<Fields>
<asp:BoundField DataField="Question_Id" HeaderText="Ticket ID" InsertVisible="False"
SortExpression="Question_I
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField DataField="DateOpened" HeaderText="Date Opened" SortExpression="Date" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField />
<asp:BoundField DataField="Questioner_Id" HeaderText="From" SortExpression="Questioner
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# Eval("Email") %>'
NavigateUrl='<%# Eval("Email", "mailto:{0}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField DataField="Urgency" HeaderText="Urgency" SortExpression="Urgency" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Status" SortExpression="Status" HeaderStyle-Font-Bold="tru
<EditItemTemplate>
<asp:DropDownList ID="StatusAssignDropDownLi
<asp:ListItem>OPEN</asp:Li
<asp:ListItem>CLOSED</asp:
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="StatusLabel" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField />
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:BoundField DataField="Detail" SortExpression="Detail" />
<asp:BoundField />
<asp:BoundField DataField="Tech_Id" HeaderText="Tech ID" SortExpression="Tech_Id" >
<HeaderStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="tru
<EditItemTemplate>
<asp:DropDownList ID="TechAssignDropDownList
DataSourceID="TechSqlDataS
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%Bind ("Tech") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TechLabel" runat="server" Text='<%# Bind ("Tech") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="DetailSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:4Life_Ma
UpdateCommand="UPDATE [sDeskQ] SET [Tech]=@Tech, [Status]=@Status
WHERE ([Question_Id] = @Question_Id)"
SelectCommand="SELECT * FROM [sDeskQ] WHERE ([Question_Id] = @Question_Id)">
<SelectParameters>
<asp:ControlParameter ControlID="TicketsGridView
PropertyName="SelectedValu
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="TicketsGridView
PropertyName="SelectedValu
<asp:Parameter Name="Status" />
<asp:Parameter Name="Tech" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="TechSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:4Life_Ma
SelectCommand="SELECT * FROM [sDeskTch]">
</asp:SqlDataSource>
<%--END TicketDetailsView and DataSource--%>
//========================
// TicketDetailsView_ItemUpda
//========================
protected void TicketDetailsView_ItemUpda
{
foreach (string key in e.NewValues.Keys)
{
Response.Write("<br>" + key + " " + e.NewValues[key]);
}
e.Cancel = true;
}
try setting the AutoPostBack=True for the dropdownlist.
ASKER
Nope that wasn't it.
Which of these two fields is having the problem:
<asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="tru e">
<EditItemTemplate>
<asp:DropDownList ID="TechAssignDropDownList " runat="server"
DataSourceID="TechSqlDataS ource"
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%Bind ("Tech") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TechLabel" runat="server" Text='<%# Bind ("Tech") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
The label or the dropdownlist?
<asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="tru
<EditItemTemplate>
<asp:DropDownList ID="TechAssignDropDownList
DataSourceID="TechSqlDataS
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%Bind ("Tech") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TechLabel" runat="server" Text='<%# Bind ("Tech") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
The label or the dropdownlist?
Well your missing a # in your databinding code:
<asp:DropDownList ID="TechAssignDropDownList " runat="server"
DataSourceID="TechSqlDataS ource"
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%Bind ("Tech") %>'
>
should be:
<asp:DropDownList ID="TechAssignDropDownList " runat="server"
DataSourceID="TechSqlDataS ource"
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%#Bind ("Tech") %>'
>
<asp:DropDownList ID="TechAssignDropDownList
DataSourceID="TechSqlDataS
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%Bind ("Tech") %>'
>
should be:
<asp:DropDownList ID="TechAssignDropDownList
DataSourceID="TechSqlDataS
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%#Bind ("Tech") %>'
>
ASKER
Yes, I spotted that. And when I fixed it I get this error.
'TechAssignDropDownList' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
thanks or taking the time to look.
'TechAssignDropDownList' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
thanks or taking the time to look.
Yes the problem is, if I understand it corectly, that you are mixing the Tech and the Tech_Id.
The Tech colum that your geting from DetailsDataSource, is it the key of the sDeskTch, or is it the name/value?
I belive the code shuld be right, but I have a huch your stroring the wrong data in the sDeskQ table.
Could you please show the table details for those 2 tables.
The Tech colum that your geting from DetailsDataSource, is it the key of the sDeskTch, or is it the name/value?
I belive the code shuld be right, but I have a huch your stroring the wrong data in the sDeskQ table.
Could you please show the table details for those 2 tables.
rundkaas' idea is correct:
You are mixing up text and value fields:
<asp:DropDownList ID="TechAssignDropDownList " runat="server"
DataSourceID="TechSqlDataS ource"
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%# Bind ("Tech") %>' <--------------- That is a Text Value, while it is trying to match it to the Tech_Id column.
>
Solution:
You will need to do an extra lookup in the database to get the correct Tech_Id value for the Tech variable, so you can set the SelectValue.
You are mixing up text and value fields:
<asp:DropDownList ID="TechAssignDropDownList
DataSourceID="TechSqlDataS
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%# Bind ("Tech") %>' <--------------- That is a Text Value, while it is trying to match it to the Tech_Id column.
>
Solution:
You will need to do an extra lookup in the database to get the correct Tech_Id value for the Tech variable, so you can set the SelectValue.
ASKER
I'm so sorry I'm not understanding. "That is a Text Value, while it is trying to match it to the Tech_Id column" I thought that the selectedValue='<%# Bind("Tech") %>' just bound the SelectedText in the dropdownbox.
Please explain "You will need to do an extra lookup in the database to get the correct Tech_Id value for the Tech variable" I thought that by identifying the DataSource (DataSourceID="TechSqlData Source") that the table values within the data source were availabe to the control.
here are my table structures
sDeskTch
-----------
Tech_Id int
Tech varchar(50)
Email varchar(50)
Password varchar(50)
sDeskQ
---------
Question_Id int
Questioner_Id varchar(100)
Tech_Id int
Tech varchar(50)
Name varchar(50)
State varchar(50)
District varchar(50)
School varchar(50)
Email varchar(50)
Type varchar(50)
Urgency varchar(50)
Subject varchar(100)
Detail varchar(1000)
Status varchar(50)
DateOpened datetime
DateClosed datetime
Please explain "You will need to do an extra lookup in the database to get the correct Tech_Id value for the Tech variable" I thought that by identifying the DataSource (DataSourceID="TechSqlData
here are my table structures
sDeskTch
-----------
Tech_Id int
Tech varchar(50)
Email varchar(50)
Password varchar(50)
sDeskQ
---------
Question_Id int
Questioner_Id varchar(100)
Tech_Id int
Tech varchar(50)
Name varchar(50)
State varchar(50)
District varchar(50)
School varchar(50)
Email varchar(50)
Type varchar(50)
Urgency varchar(50)
Subject varchar(100)
Detail varchar(1000)
Status varchar(50)
DateOpened datetime
DateClosed datetime
well I think I must disagree with existenz2 on the point of solution!
It is much more normalized to store the key instead of a name in the table.
Your Tech field in the sDeskQ table should be an int, and not a varchar(or similar), this way you can avoid the extra lookup.
It is much more normalized to store the key instead of a name in the table.
Your Tech field in the sDeskQ table should be an int, and not a varchar(or similar), this way you can avoid the extra lookup.
As I can see from your database structure, you should not have both Tech and Tech_Id in sDeskQ. It is enough with one, an int thats stores the primary key in sDeskTch.
This way you negate the need to update 2 tech fields, as there is now just one.
This way you negate the need to update 2 tech fields, as there is now just one.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, I see the point on normalizing the db. Tech_Id is new primary key of the sDeskTch table. Tech is that actual name of the Tech.
I just wanted to have the values (Tech_Id and Tech) in both fields for the sake of accessibility. I could fix this accessiblity issue by using views.
Ok, I will normalize the DB so that sDeckQ only has the Tech_Id in it.
Now a problem arises, I still need the tech name to show in the DetailsView. I have the datasource for the detailsview as sDeskQ, how am I going to pull the tech name (Tech) into the details view if I no longer have that value in the datasource.
I still want the user to be able to pick the tech by name (Tech in sDeskTch) even though the Tech_Id will be value written to sDeskQ. I'm feeling so frustrated.
I'm feeling so frustrated. I first just used the wizard to generate the Gridview and Detailsview, but then I decided I needed to understand how it worked so I rewrote them by hand. Taking time to look at each section of code and understand how it works. I feel I must be missing something, some concept. I'm just so damn new to this ASP.NET coding.
You can see a diagram of the new database design here www.myschoolfees.com/images/dbDiagram.jpg
Thanks for all your help and patience. I'm going to keep working on the code and see what I can do. But if you can offer me anymore examples, and answers to questions, that would be awesome.
Thanks so much, Bill
I just wanted to have the values (Tech_Id and Tech) in both fields for the sake of accessibility. I could fix this accessiblity issue by using views.
Ok, I will normalize the DB so that sDeckQ only has the Tech_Id in it.
Now a problem arises, I still need the tech name to show in the DetailsView. I have the datasource for the detailsview as sDeskQ, how am I going to pull the tech name (Tech) into the details view if I no longer have that value in the datasource.
I still want the user to be able to pick the tech by name (Tech in sDeskTch) even though the Tech_Id will be value written to sDeskQ. I'm feeling so frustrated.
I'm feeling so frustrated. I first just used the wizard to generate the Gridview and Detailsview, but then I decided I needed to understand how it worked so I rewrote them by hand. Taking time to look at each section of code and understand how it works. I feel I must be missing something, some concept. I'm just so damn new to this ASP.NET coding.
You can see a diagram of the new database design here www.myschoolfees.com/images/dbDiagram.jpg
Thanks for all your help and patience. I'm going to keep working on the code and see what I can do. But if you can offer me anymore examples, and answers to questions, that would be awesome.
Thanks so much, Bill
select q.*, t.Tech from sDeskQ q inner join sDeskTch t on ( q.Tech_Id = q.Tech_Id)
There is no problem pulling information out of more than 1 table, and this does not by fare make it unnormalized!
Pull this information out, Eval the Tech ( description/Name) in the item template, and Bind the Tech_Id to the dropdownlist in edit.
<asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="tru e">
<EditItemTemplate>
<asp:DropDownList ID="TechAssignDropDownList " runat="server"
DataSourceID="TechSqlDataS ource"
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%# Bind ("Tech_Id") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TechLabel" runat="server" Text='<%# Eval("Tech") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
There is no problem pulling information out of more than 1 table, and this does not by fare make it unnormalized!
Pull this information out, Eval the Tech ( description/Name) in the item template, and Bind the Tech_Id to the dropdownlist in edit.
<asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="tru
<EditItemTemplate>
<asp:DropDownList ID="TechAssignDropDownList
DataSourceID="TechSqlDataS
DataTextField="Tech" DataValueField="Tech_Id"
SelectValue='<%# Bind ("Tech_Id") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TechLabel" runat="server" Text='<%# Eval("Tech") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
The sql should of course be:
select q.*, t.Tech from sDeskQ q inner join sDeskTch t on ( q.Tech_Id = t.Tech_Id)
select q.*, t.Tech from sDeskQ q inner join sDeskTch t on ( q.Tech_Id = t.Tech_Id)