|
-
January 31st, 2012, 01:13 PM
#1
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference()
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.
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 the gridview rows.
Code:
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()));
}
}
...setup of selectedIndexChanged on gridview
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.
-= the best is yet to come =-
-
January 31st, 2012, 05:04 PM
#2
Re: e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference()
I have done this sort of thing with javascript (client side)... something like this...
C#
Code:
e.Row.Attributes.Add("onclick", "javascript:SetTxtbxText(this.TextBox1, '" + GridView1.SelectedValue.ToString() + "');");
aspx
Code:
<script type="text/javascript">
<!--
function SetTxtbxText(Txtbx, text)
{
Txtbx.innerHTML = text;
}
//-->
</script>
To be honest, I didn't try that exact thing... But something close. I hope that helps...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|