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: 361
  • Last Modified:

Need help with EDIT updates in an ASP.NET Gridview...

Have an ASP.NET GridView...  4 columns, with autogenerated EDIT column.

                <asp:GridView ID="ContactGridView" runat="server"
                    AutoGenerateColumns="False"
                    BackColor="#DEBA84" 
                    BorderColor="#DEBA84" 
                    BorderStyle="None" 
                    BorderWidth="1px" 
                    CellPadding="5"
                    CellSpacing="3"
                    DataKeyNames="ContactUs_key"
                    DataSourceID="SqlDataSource1"
                    HeaderStyle-HorizontalAlign="Center"
                    HeaderStyle-Wrap="True"
                    HorizontalAlign="Center"
                    onselectedindexchanged="ContactGridView_SelectedIndexChanged"
                    SelectedRowStyle-BackColor="Wheat" >
                    <Columns>
                        <asp:CommandField ShowEditButton="True" />
                        <asp:BoundField DataField="ContactUs_key" HeaderText="Key" ItemStyle-HorizontalAlign="Center" ReadOnly="True" InsertVisible="False" SortExpression="ContactUs_key" Visible="false" >
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="Status" SortExpression="ContactUs_status">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" SelectedValue='<%# Bind("ContactUs_status", "{0}") %>'>
                                    <asp:ListItem Value="I">In Progress</asp:ListItem>
                                    <asp:ListItem Value="C">Complete</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ContactUs_status") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="ContactUs_last_name" HeaderText="Last Name" SortExpression="ContactUs_last_name" ReadOnly="true" />
                        <asp:BoundField DataField="ContactUs_processedDate" HeaderText="Last Update" SortExpression="ContactUs_processedDate" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="Center" >
                        <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="ContactUs_processedBy" HeaderText="Updated By" SortExpression="ContactUs_processedBy" ItemStyle-HorizontalAlign="Center" >
                        <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>

Open in new window



I have Edit Button, Status, Processed Date and Processed By  columns.

If the edit option is used to change the status.  I just want to plug the 2 "Processed" fields with data.
Plug the DATE with Date.NOW  and use a hidden.control.text  value for the BY column.

I thik that it has something to do with the "onselectedindexchanged" option.  I would basically write my own SQL code for that in the code-behind, but HOW do I get the right column updated as it should be?

Bob
0
Bob Bender
Asked:
Bob Bender
  • 4
  • 2
1 Solution
 
sammySeltzerCommented:
Hi,

Your question is very difficult to understand.
0
 
Bob BenderAuthor Commented:
Oh, in what way????  

Lemme try English....   ROFL

I have multiple columns...   "Edit Button", "Status", "Processed Date" and "Processed By".

If the Edit Button is used to change the record....   I can change the other 3 columns.... "Status", "Processed Date" and "Processed By".

Instead of actually changing  the "Processed Date" and "Processed By", I want to just "plug" those fields with valid data and not rely on the user to fill it in correctly....

I have tried various method options within the GridView,  (like onrowupdated, onrowupdating, onselectedindex, etc)  

All things I have done in the past are referenced by columns, with a 0 relative base,   NOT 1-9, but 0-8.   But, the combination of column "index" and what stage in the process to "plug" the data confuses me....

I could go into the database and UPDATE the fields and re-bind the GridView on the page..  

It would be cleaner (and learning more) to let the changes be made when handling the EDIT/UPDATE processes of GridView...

Clearer?
0
 
sammySeltzerCommented:
Lemme try English....   ROFL


First of all, you need to understand that there are exceptionally talented helpers here at EE.

So, if there are no attempts at answering your question, one of the most common reasons is that your question is not clear enough for anyone to attempt an answer.

So, to suggest that your question is so clear and it is us who have problem understanding it is a bit condensing.

I use every opportunity that I have to remind those seeking help that *we* provide this help absolutely free.

I am not obligated in any way to help you or anyone.

I am motivated to help because I have been helped many times by those who abandon the work that pays them to help.

NOW, having said this, your ability to have cascading updates based on a set of criteria is based largely on your data structure.

So, to change the value of one field and then have the values of associated fields change is based on the relationship between them.

Yes, it has to do with onselectedindexchanged.

For instance, assume I have a dropdownlist control like below:

 <asp:DropDownList ID="drop1" OnSelectedIndexChanged="drop1_SelectedIndexChanged" runat="server" CssClass="style26" AutoPostBack="True" />

Open in new window


Assume you wish to auto fill form field called myname:

     <strong>Fill Name</strong>Auto filled name)<br /><br /> </span>
                <asp:TextBox ID="myname" runat="server" CssClass="style26"></asp:TextBox>

Open in new window



Then the meat:

    Sub drop1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        myname.Text = CType(sender, DropDownList).SelectedValue

        'Did I get what I asked for?
        Response.Write(myname)
        Response.End()
    End Sub

Open in new window


Example above is based on passing same value from dropdown to myname.Text control.

In your case, you will assign associated value from your database to a recordset inside the drop1_SelectedIndexChanged() sub, something along the lines of:

   Dim connStr As String = ConfigurationManager.ConnectionStrings("Database_DBConnectionString").ConnectionString

       sqlStr = "SELECT * FROM yourtable WHERE id= drop1.selectedValue

      cnn = New SqlConnection(connStr)
     cnn.Open()
   cmd = New SqlCommand(sqlStr, cnn)

   Dim dreader = cmd.ExecuteReader()

      If dreader.Read() Then
          fullname = dreader.GetString(0)
    End If
    dreader.Close()

'Finally, pass value back to the textbox control associated with drop1

myname.Text = fullname

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bob BenderAuthor Commented:
TYou said....
So, to suggest that your question is so clear and it is us who have problem understanding it is a bit condensing.


Sammy,  Just an FYI... the word is condescending, not condensing..

And IMHO, I never said it was so clear that anyone could understand it.  You did, so please do not put words in my mouth (apologies if you are offended by this point of view)  Gee whiz, a person cant have a slight sense of humor

I clarified the comments and description to best of my Junior capabilities.  I' have to review the rest of your reply at the PC where the devl is being done, as I have no access to the db to test outside the environment.

As for "neglect and abandoning" the post.  maybe my marriage was not so important to put things on hold here.
That's a joke son (as Foghorn Leghorn used to say in the cartoons in the 70s)
0
 
Bob BenderAuthor Commented:
Okay, your code and "understanding" of my question is not clear.

I have a GRIDVIEW....  I change Column 2 (say status) using a drop-down box (this works).

As I make that change...  I ALSO want to default Columns 9 (Date Changed) and Columns 10 (Changed By).   I want the new values to be shown on The Gridview after using the UPDATE link.

You seem to be changing a TextBox by the value associated with a drodown.  Nothing like I need.  

Also, the question was a C# condition and it seems that this is VB code. (but should be easy to change, had it applied.)

Bob
0
 
Bob BenderAuthor Commented:
Unable to delete

I solved it thru use of the Find.Control and binding to it
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now