EDN Admin
Well-known member
I have created a datagrid bound to a table. it only uses two fields (name, model). They bind and display fine. the thing is, I want the user to be able to comment in a third field column, regarding the first column.
I dont want to permanently save the comment. it is only to be used within the context of the screen displays when changing pages. Thus for now there are 50 items which break into 5 pages showing 10 items each.
And I dont wish to use the edit, delete, update columns. Its messy. It should be similar to excel, you go to the item you want to change and type in whatever you want to post.
So for example. The 1st column row 3 might display honda accord. In column 3, to the right I might want to say its red and costs $5000.
The value holds until changing page. I can create a script and tease out the value on the cleint side. Here is the code:
<span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <font face="Consolas" size="2" color="#0000ff" style="color:#0000ff; font-family:Consolas; font-size:x-small
<div style="color:Black;background-color:White; <pre>
<script type=<span style="color:#A31515; "text/javascript">
<span style="color:Blue; function displaymessage() {
<span style="color:Blue; var gv = document.getElementById(<span style="color:#A31515; "MainContent_GridView1");
<span style="color:Blue; var tb = gv.getElementsByTagName(<span style="color:#A31515; "input");
<span style="color:Blue; var tbLength = tb.length;
<span style="color:Blue; var strTemp = tb[1].value;
}
<script>
[/code]
</font>
(Note MainContent_ prefix on gridview probably needed because working iwth masterpages. )
But I am unable to find the value on the server side and it is not clear as to how best to save the view and values for subsequent redisplay. That is to say, if you fill column 3 all the rows with different values; if you go to page 5 and then back
to page 1 all the values will be lost. Where and when and how shoukd the comments be saved. Ive read quite a bit on this and this specific example isnt commented on and related discussions seem to get close but not bulls eye. Talks
of using viewstate - but when debugging have not been able to see the gridview values in the viewstate.
Thanks (also dont see how tpo control font size on this board)
<pre> <tr>
<td class="style5" colspan="2
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="name" DataSourceID="SqlDataSource1" Height="307px"
Width="720px" AllowPaging="True" AllowSorting="True
<Columns>
<asp:BoundField DataField="name" HeaderText="name" ReadOnly="True"
SortExpression="name" />
<asp:BoundField DataField="model" HeaderText="model"
SortExpression="model" Visible="False" />
<asp:TemplateField HeaderText="Your Answer
<ItemTemplate>
<asp:TextBox ID="txtAnswer" runat="server"
onclick="displaymessage();" AutoPostBack="True
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField> [/code]
View the full article
I dont want to permanently save the comment. it is only to be used within the context of the screen displays when changing pages. Thus for now there are 50 items which break into 5 pages showing 10 items each.
And I dont wish to use the edit, delete, update columns. Its messy. It should be similar to excel, you go to the item you want to change and type in whatever you want to post.
So for example. The 1st column row 3 might display honda accord. In column 3, to the right I might want to say its red and costs $5000.
The value holds until changing page. I can create a script and tease out the value on the cleint side. Here is the code:
<span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <span style="color:#0000ff; font-family:Consolas; font-size:x-small <font face="Consolas" size="2" color="#0000ff" style="color:#0000ff; font-family:Consolas; font-size:x-small
<div style="color:Black;background-color:White; <pre>
<script type=<span style="color:#A31515; "text/javascript">
<span style="color:Blue; function displaymessage() {
<span style="color:Blue; var gv = document.getElementById(<span style="color:#A31515; "MainContent_GridView1");
<span style="color:Blue; var tb = gv.getElementsByTagName(<span style="color:#A31515; "input");
<span style="color:Blue; var tbLength = tb.length;
<span style="color:Blue; var strTemp = tb[1].value;
}
<script>
[/code]
</font>
(Note MainContent_ prefix on gridview probably needed because working iwth masterpages. )
But I am unable to find the value on the server side and it is not clear as to how best to save the view and values for subsequent redisplay. That is to say, if you fill column 3 all the rows with different values; if you go to page 5 and then back
to page 1 all the values will be lost. Where and when and how shoukd the comments be saved. Ive read quite a bit on this and this specific example isnt commented on and related discussions seem to get close but not bulls eye. Talks
of using viewstate - but when debugging have not been able to see the gridview values in the viewstate.
Thanks (also dont see how tpo control font size on this board)
<pre> <tr>
<td class="style5" colspan="2
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="name" DataSourceID="SqlDataSource1" Height="307px"
Width="720px" AllowPaging="True" AllowSorting="True
<Columns>
<asp:BoundField DataField="name" HeaderText="name" ReadOnly="True"
SortExpression="name" />
<asp:BoundField DataField="model" HeaderText="model"
SortExpression="model" Visible="False" />
<asp:TemplateField HeaderText="Your Answer
<ItemTemplate>
<asp:TextBox ID="txtAnswer" runat="server"
onclick="displaymessage();" AutoPostBack="True
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField> [/code]
View the full article