Am I missing something somewhere?!
I'm trying to use a GridView that is bounded to a dataset as when a row is clicked, an event (or postback?) is fired. When fired, I want some data associated with the clicked row to then populate a textbox found elsewhere on the aspx page. It looks as if everything is working...until I don't see anything in the referenced text box.
...setup my gridview.
...setup the gridview rows.Code:<asp:GridView ID="GridView1" runat="server" onselectedindexchanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="false" GridLines="Both" Width="600" PageSize="400" onrowdatabound="GridView1_RowDataBound"> <Columns><asp:BoundField DataField="sender" HeaderText="From" /> <asp:BoundField DataField="date_created" HeaderText="Date" /> <asp:BoundField DataField="message" HeaderText="Message" ItemStyle-Width="400" ItemStyle-Wrap="false" /> </Columns> </asp:GridView>
...setup of selectedIndexChanged on gridviewCode:protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand'; this.style.backgroundColor='lightpink';") ; e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';"); e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(this.TextBox1, "Select$" + e.Row.RowIndex.ToString())); } }
Code:protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { this.TextBox1.Text = this.GridView1.SelectedValue.ToString(); }
I think this is all I need. my textbox is TextBox1 and when trying to change the text property to the selected value of the gridview, nothing. In fact, my breakpoint for that method seems to not fire at all. Am I missing something here?? When I do click on the row, I see the page flicker so it is doing something, but not quite doing exactly as I thought.
Can any one shed some light on this? I just need another step deeper in explaination as opposed to what I'm finding in my searches.




Reply With Quote