I am attempting to create a table with a checkbox, an image, and an image title in each cell.
I created the table statically with no values in the cell items.
I then dynamically fill in each cell.
When I click a checkbox in the cell, the page flickers for the first 2 check boxes, then on the 3rd and subsequent clicks it repaints the whole table.
I added a RadScriptManager, but it appears to have had no effect.
I do nothing on the Page Load postback except load a few variables from the Session state.
This is part of my ASPX page.
<asp:Table ID="tblItems" runat="server" GridLines="Both" Width="98%" >
<asp:TableRow ID ="tr1" runat="server" Visible="false">
<asp:TableCell ID="tcR1C1" runat="server">
<asp:CheckBox ID="cbR1C1" runat="server"
OnCheckedChanged="cb_CheckedChanged" AutoPostBack="true" />
<asp:Label ID="lblR1C1" runat="server" />
<br />
<asp:Image ID="imgR1C1" runat="server" Width="200px" Height="200px" />
</asp:TableCell>
this is part of my initial load page
lbl.Text = lProducts.Products[iCurrentProduct].title;
img.ImageUrl = lProducts.Products[iCurrentProduct].image.src;
I am initially loading the object from an http://. Not sure if that is the issue. I could get each item locally as an image, then put it in the table, but I think the table should not be updating all the time - I thought that is what the RadScriptManager was supposed to do?
Related
I have a Gridview set up and populated by binding my data. I have created a column that holds an "Edit" button. Clicking that button changes all of my fields to a text box populated with the data that is pulled from the database and replaces the "Edit" button with an "Update" and "Cancel" button. Up to this point all is working as intended. I change the value in the textboxes that I want to update and click the "Update" button. At this point everything is cleared out of all of the text boxes in each cell. I can enter the data again at this point and click the "Update" button a second time and any values that I have entered (the second time) will be passed back to my updating event procedure, but that is not quite the functionality I'm looking for.
I have run across a couple reports of the "Edit" button requiring 2 clicks to function, but the fixes didn't really apply to my situation.
This is my page_load
{
if (!this.IsPostBack)
{
Build_DDL();
Build_Turn_Checkbox_List();
Show_Data();
}
CheckBox_Selected_Values();
}
This is my gridview declaration:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" HeaderStyle-CssClass="headerClass" HeaderStyle-VerticalAlign="Bottom"
RowStyle-Wrap="true" HeaderStyle-Wrap="true" OnDataBound ="OnDataBound" AllowSorting="True" HeaderStyle-Height="50px"
OnSorting="GridView1_SelectedIndexChanged" CssClass="reportData" OnRowDataBound="GridView_OnRowDataBound"
OnRowCancelingEdit="GridView1_RowCancelEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<HeaderStyle VerticalAlign="Bottom" Wrap="True" Height="50px" />
<RowStyle Wrap="True" CssClass="oddRow" />
<AlternatingRowStyle CssClass="evenRow" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID ="btn_Edit" runat="server" Text="Edit" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btn_Update" runat="server" Text="Update" CommandName="Update"/>
<asp:Button ID="btn_Cancel" runat="server" Text="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="State" Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_state" runat="server" Text='<%#Eval("STATE") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_state" runat="server" Text='<%#Eval("STATE") %>'></asp:TextBox>
</EditItemTemplate>
There are more fields, but they are all built exactly the same.
Here is my update code:
{
//declare variables
string stateVal;
//set up textboxes
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox txt_State = (TextBox)row.FindControl("txt_state");
stateVal = txt_State.Text;
}
I didn't notice that when I clicked the "Edit" button on row 2, it was row 5 that was transitioning into text boxes. This was because I have the following code creating groupings in the gridview and each group creates a new row that is not accounted for in the row index scheme:
helper.RegisterGroup("State", true, true);
helper.RegisterGroup("Project Type", true, true);
helper.GroupHeader += new GroupEvent(Helper_GroupHeader);
helper.ApplyGroupSort();
GridView1.DataBind();
I will have to somehow account for the group headers and adjust the neweditindex accordingly.
I need to make filters on table (GridView), on the top of each column should appear "TextBox" to enter filter values. GridView width is not fixed, column's width always changing depending on results. How to make that TextBox width on top of columns auto changed when GridView's columns width changing?
As you see in image, there are 3 columns. White - TextBoxes (for filtering data), yellow - GridView
This is my current code:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="InsertName" runat="server" width="130px" placeholder="Name Filter..."></asp:TextBox>
<asp:TextBox ID="InsertEmail" runat="server" width="130px" placeholder="Domain Filter..."></asp:TextBox>
<asp:TextBox ID="InsertCountry" runat="server" width="130px" placeholder="Domain Filter..."></asp:TextBox>
<br />
<br />
</div>
<asp:GridView ID="GridView1" runat="server" BackColor="#FFFFB3" width="390px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
</asp:GridView>
</form>
Here I set fixed widths for each TextBox and for GridView. But here is problem, GridView have fixed width as I wrote width="390px", but columns width always changing. Have you ideas?
You cannot accomplish this in the current HTML markup since the DIV containing the text boxes is unaware of the GridView resizing.
Instead, you could use a HeaderTemplate inside a TemplateField like this (with a 100% text box width):
<asp:GridView ID="GridView1" runat="server" BackColor="#FFFFB3" width="390px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
...
<asp:TemplateField HeaderText="Name">
<HeaderTemplate>
<asp:TextBox ID="InsertName" runat="server" width="100%" placeholder="Name Filter..."></asp:TextBox>
</HeaderTemplate>
<ItemTemplate>
...
</ItemTemplate>
</asp:TemplateField>
...
</Columns>
</asp:GridView>
I've got something like that
<asp:ListView ID="lv" runat="server">
<LayoutTemplate>
<asp:Literal ID="litControlTitle" runat="server" />
<label id="test" runat="server">dw</label>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:ListView>
Can someone tell me, how should I change label text, using C# code?
Main problem for me is- how to get access to the nested control (label, literal) from c# code?
EDITED:
<SelectedItemTemplate>
<asp:HiddenField ID="NumberEdit" runat="server"
Value='<%# Bind("numbers") %>' />
<label for="NameEdit">Name:</label>
<asp:TextBox ID="NameEdit" Width="160px" runat="server" AutoPostBack="true" OnTextChanged="NameEdit_TextChanged"
Text='<%# Bind("Name") %>' />
<br />
<label for="ShortcutEdit">Shortcut:</label>
<asp:TextBox ID="ShortcutEdit" Width="80px" runat="server"
Text='<%# Bind("Shortcut") %>' />
<br />
and I would like to generate automatically Shortcut text when user will change Name (Shortcut = 2 first letters from NameEdit)? Can you explain me, how should I do it? –
You would want to have an ItemDataBound event handler to get access to the controls for that particular item in your listview. The example on the page I linked should help you out.
First thing is that you need a data source binded with this ListView control, for example SqlDataSource, or any other allowed type you need:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:YourConnectionString %>"
SelectCommand="SELECT [Title], [id] FROM [Articles]"></asp:SqlDataSource>
<asp:ListView ID="lv" runat="server" DataSourceID="SqlDataSource1" >
// rest of the code
</asp:ListView>
Second thing is that controls from LayoutTemplate template will be rendered only if there is any data to show. So if you have datasource, but it is empty, this tamplate will not be applied. But you can use EmptyDataTemplate to display info when there is nothing from the datasource to display.
And then, when you already have datasource defined and binded to your ListView and there is data that will be displayed, the LayoutTemplate will be rendered. And then you can use FindControl method of the ListView. As for example of getting this literal:
Literal l = (Literal)lv.FindControl("litControlTitle");
It's returning null for you because you have no data to display, so controls are not rendered at all.
((Label)ListView1.FindControl("test")).Text = "Hello!";
I have a gridview which has a few rows (each with a unique rowId), and each line has a FileUpload control, now everything works okay with FileUpload.
(my uploaded file database image can be seen below)
I have the download button, which also works okay, however I want to make this button invisible if no file exists for the corresponding row.
Nothing proper comes to my mind.
My button and FileUpload control:
<asp:TemplateField HeaderText="BatchList">
<EditItemTemplate>
<asp:ImageButton ID="ibt_Download" runat="server" src="Images/Download.png" CommandName="Download" CommandArgument='<%# Container.DataItemIndex %>' ></asp:ImageButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UploadBatchList">
<HeaderTemplate>
<asp:Label ID="lbl_Header" ToolTip="Upload Batch List" runat="server" Text="UBL"></asp:Label>
</HeaderTemplate>
<EditItemTemplate>
<asp:FileUpload ID="fu_UploadBatchList" runat="server" />
<asp:Button ID="btn_Upload" runat="server" Text="Upload" OnClick="btn_Upload_Click" />
</EditItemTemplate>
</asp:TemplateField>
This is how it looks on my gridView
When gridview is first created the green dots must not be visible if a file has been uploaded before.
My file database:
You can check some property of the data item (DocName in your case) if it contains a value (it might not work when copy-pasted, I'm a little bit improvising):
<asp:Button ID="btn_Upload" runat="server"
Text="Upload"
Visible='<% DataBinder.Eval(Container.DataItem, "DocName") == null %>
OnClick="btn_Upload_Click" />
Or you can create a function that will evaluate the visibility. See Mastering ASP.NET DataBinding for more.
I am programming using .NET aspx. In the asp:DataList component I want to distribute columns evenly, even in case not all columns are assigned an ItemTemplate.
E.g.
<asp:DataList id="test" runat="server" Width="90%" gridlines="None"
RepeatDirection="Horizontal"
RepeatColumns="4" HorizontalAlign="Left">
<ItemTemplate> ... </ItemTemplate>
</asp:DataList>
At runtime the array bound to the datalist only contains 2 elements. I still want the columns to be distributed evenly over the four spaces.
If you are dedicated to using a DataList, there are two reasonable methods for accomplishing this.
First, you can wrap your ItemTemplate in a div with a fixed width.
<ItemTemplate>
<div style="width: 250px;">
...
</div>
</ItemTemplate>
Secondly, if your DataList must expand or contract to fit the viewer's screen, you can utilize jquery.
We will be grabbing the computed client width of the datalist after page load and adjusting the columns to be distributed evenly.
<asp:DataList id="MyDataList" ClientIDMode="Static" runat="server" Width="90%" gridlines="None"
RepeatDirection="Horizontal"
RepeatColumns="4" HorizontalAlign="Left">
<ItemTemplate>
<div class="DataListItem">
....
</div>
</ItemTemplate>
</asp:DataList>
Two quick notes before we see the jquery
ClientIDMode="Static" on the datalist
Every datalist item will be wrapped in a div with class "DataListColumn"
In jquery, upon page load, you can get the computed datalist width as follows
$(document).ready(function () {
$(".DataListItem").width($("#MyDataList").width() / 4); // Set the column width
});
With all of that said, you may want to just use a repeater so you can have more control over actual columns.