Solved

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

Posted on 2014-10-23
6
321 Views
Last Modified: 2014-11-25
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
Comment
Question by:Bob Bender
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
Hi,

Your question is very difficult to understand.
0
 
LVL 5

Author Comment

by:Bob Bender
Comment Utility
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
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Author Comment

by:Bob Bender
Comment Utility
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
 
LVL 5

Accepted Solution

by:
Bob Bender earned 0 total points
Comment Utility
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
 
LVL 5

Author Closing Comment

by:Bob Bender
Comment Utility
Unable to delete

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now