sadee52
asked on
dropdown and textbox in gridview Edit mode
I have 2 dropdownlists and a textbox in Editmode template.
2 dropdownlist is basically to get hours and minutes. I want dropdown selected value to be display in textbox. and then new value in textbox should be updated when i click on update
2 dropdownlist is basically to get hours and minutes. I want dropdown selected value to be display in textbox. and then new value in textbox should be updated when i click on update
if you need on client side then In RowDataBound Event add attribute to your Dropdownlist to show selected value in TextBox and on update event find the textbox from the gridview and update back to database.
if you want to do using server side then you need to handle bubbled events for dropdownlists .. that would a big overhead posting page back on every selection.
if you want to do using server side then you need to handle bubbled events for dropdownlists .. that would a big overhead posting page back on every selection.
ASKER
i have a grid view when user click edit then in edit mode in addition to textbox field i want two dropdownlist
one for hours input other for minutes input. when user enter hour and minutes it should be displayed in textbox as eg 3:23
one for hours input other for minutes input. when user enter hour and minutes it should be displayed in textbox as eg 3:23
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanx Mortaza half of the problem solved but how can i update the new txt.Text to my database.
You can write a an sql query to do that, assume that your table's name is Table1 and the field which is needed to be updated is: Time_vc and the primary key which the update should be based on that is ID.
Dim SQL As String = "UPDATE Table1 SET Time_vc=@Time_vc WHERE ID=@ID"
Dim cnn As New Data.SqlClient.SqlConnection
Dim cmd As New Data.SqlClient.SqlCommand
cnn.ConnectionString = "<Your Connection String>"
cmd.Connection = cnn
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = SQL
Dim P1 As New Data.SqlClient.SqlParameter("@Time_vc", Data.SqlDbType.VarChar, 10)
P1.Value = txt.Text
Dim P2 As New Data.SqlClient.SqlParameter("@Time_vc", Data.SqlDbType.VarChar, 10)
P2.Value = GridView1.SelectedDataKey
cmd.Parameters.Add(P1)
cmd.Parameters.Add(P2)
Try
cnn.Open()
cmd.ExecuteNonQuery()
Finally
cnn.Close()
cmd.Dispose()
cnn.Dispose()
End Try
Sorry, line 15 should change to:
Dim P2 As New Data.SqlClient.SqlParameter("@ID", Data.SqlDbType.Int)
Or alternatively if you used DataSource controls such as SQLDataSource, you can specify the update command and it does the updating automatically for you.
ASKER
Thanks murtaza but i am using gridview. and
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("StartTime") %>'></asp:TextBox><br />
...
</EditItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("StartTime") %>'></asp:TextBox><br />
...
</EditItemTemplate>
NP, '<%# Bind("StartTime") %>' is a two way binding, means that you can update the text box value and see it reflected in your database.
Could you please give more detailed information on this?