Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

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="DetailSqlDataSource"
                 DataKeyNames="Question_Id" AutoGenerateRows="False"
                 OnItemUpdating="TicketDetailsView_ItemUpdating"
                 >
  <Fields>
    <asp:BoundField DataField="Question_Id" HeaderText="Ticket ID" InsertVisible="False"
                    SortExpression="Question_Id" >
      <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="true">
      <EditItemTemplate>
        <asp:DropDownList ID="StatusAssignDropDownList" runat="server" SelectedValue='<%# Bind("Status") %>'>
          <asp:ListItem>OPEN</asp:ListItem>
          <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="true">
      <EditItemTemplate>
        <asp:DropDownList ID="TechAssignDropDownList"  runat="server"
                          DataSourceID="TechSqlDataSource"
                          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_MasterConnectionString %>"
                   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="SelectedValue" Type="Int32" />
  </SelectParameters>
  <UpdateParameters>
    <asp:ControlParameter ControlID="TicketsGridView" Name="Question_Id"
                                       PropertyName="SelectedValue" Type="Int32" />
    <asp:Parameter Name="Status" />
    <asp:Parameter Name="Tech" />
  </UpdateParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="TechSqlDataSource" runat="server"
                   ConnectionString="<%$ ConnectionStrings:4Life_MasterConnectionString %>"
                   SelectCommand="SELECT * FROM [sDeskTch]">
</asp:SqlDataSource>
<%--END TicketDetailsView and DataSource--%>



  //===============================================
  // TicketDetailsView_ItemUpdating()
  //===============================================
  protected void TicketDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
  {
    foreach (string key in e.NewValues.Keys)
    {
      Response.Write("<br>" + key + " " + e.NewValues[key]);
    }

    e.Cancel = true;
  }
0
tatton777
Asked:
tatton777
  • 7
  • 4
  • 3
  • +1
2 Solutions
 
mirmansoorCommented:
try setting the AutoPostBack=True for the dropdownlist.
0
 
tatton777Author Commented:
Nope that wasn't it.
0
 
existenz2Commented:
Which of these two fields is having the problem:

 <asp:TemplateField HeaderText="Tech" SortExpression="Tech" HeaderStyle-Font-Bold="true">
      <EditItemTemplate>
        <asp:DropDownList ID="TechAssignDropDownList"  runat="server"
                          DataSourceID="TechSqlDataSource"
                          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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rundkaasCommented:
Well your missing a # in your databinding code:
<asp:DropDownList ID="TechAssignDropDownList"  runat="server"
                          DataSourceID="TechSqlDataSource"
                          DataTextField="Tech" DataValueField="Tech_Id"
                          SelectValue='<%Bind ("Tech") %>'
                          >
should be:
<asp:DropDownList ID="TechAssignDropDownList"  runat="server"
                          DataSourceID="TechSqlDataSource"
                          DataTextField="Tech" DataValueField="Tech_Id"
                          SelectValue='<%#Bind ("Tech") %>'
                          >
0
 
tatton777Author Commented:
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.
0
 
rundkaasCommented:
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.
0
 
existenz2Commented:
rundkaas' idea is correct:

You are mixing up text and value fields:

<asp:DropDownList ID="TechAssignDropDownList"  runat="server"
                          DataSourceID="TechSqlDataSource"
                          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.
0
 
tatton777Author Commented:
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="TechSqlDataSource") 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
0
 
rundkaasCommented:
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.
0
 
rundkaasCommented:
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.
0
 
existenz2Commented:
@rundkaas:
Value fields are meant to be unique, Text fields don't have to be unique. If they are unique, there has been made a design flaw in the database and business model. Which you suggest also in your last post. But to solve this without redesigning the database the solution with a extra database roundtrip is needed.
0
 
rundkaasCommented:
@existenze2
True, and both solutions are viable, now it is just up to tatton777 to deside what to do:
1: He could fix the database by normalizing it, or
2: He could evade the problem as you descibed
0
 
tatton777Author Commented:
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
0
 
rundkaasCommented:
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="true">
      <EditItemTemplate>
        <asp:DropDownList ID="TechAssignDropDownList"  runat="server"
                          DataSourceID="TechSqlDataSource"
                          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>
0
 
rundkaasCommented:
The sql should of course be:
select q.*, t.Tech from sDeskQ q inner join sDeskTch t on ( q.Tech_Id = t.Tech_Id)
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.

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now