>>>>>>>>On the same page I have a GridView bound to a dataset. Below the GridView there is a textbox (or several textboxes). As user navigates through the GridView (clicking on this or that row) I want the value/text in the textbox(s) to be updated according to new row in the dataset. My understanding is I need to bind the textbox(s) to the same dataset. How do you do it? An example, of one textbox binding to the dataset would be very helpful.
>>>>>>>
>>>>>>>If you don't mind round-tripping to the server you can wire up the GridView.SelectedIndexChanged event and do something like this:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
>>>>>>> {
>>>>>>> TextBox1.Text = GridView1.SelectedRow.Cells[2].Text;
>>>>>>> //etc
>>>>>>> }
>>>>>>
>>>>>>I prefer not to make the "trip" back to the server. I am working on having a button field on the GridView and wire it to a method of the page. The only thing I don't know - yet - if the page has to be reposted on the call to this method. If so I will look for way to do it with jQuery so there is no reposting of the page and no trip back to the server.
>>>>>>Thank you.
>>>>>
>>>>>Not quite so easy. Wire up the GridView.RowDataBound event in c#:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
>>>>> {
>>>>> if (e.Row.RowType == DataControlRowType.DataRow)
>>>>> {
>>>>> e.Row.Attributes.Add("onClick", "javascript:void selectRow(this);");
>>>>> }
>>>>> }
then script on the page:
function selectRow(i) {
>>>>> document.getElementById("TextBox1").value = i.cells[5].innerText;
>>>>> }
>>>>
>>>>Thank you very much. I will try to "translate" your code into jQuery code. I have been studying jQuery over the weekend and am anxious to try it.
>>>jQuery would just be :
function selectRow(i) {
>>> $('#TextBox1').val(i.cells[5].innerText);
>>> }
TBH, when I need this type of functionality now I use WebAPI and angular. angular gives you a nice MVVM two-way binding on the client.
>>
>>Thank you for the example of using jQuery.
>>As to WebAPI and angular, this is the first time I hear about these technologies. You mentioned MVVM but will WebAPI and angular work on ASP.NET Web Forms, as far as you know?
>
>You can use it in a Web Forms application - but where it *is* being used a simple HTML page is probably easier to work with than using a Web Form (aspx) page.
Thank you. A lot to learn. And I found a couple of tutorials that I will go through at some point.
Right now I am trying to figure how to pass to a jQuery function the row object values of GridView. I think I need to learn JSON for that or maybe something else. My head is spinning.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham