How do layout how items are shown in asp gridview? - asp.net

I'd like to change the way gridview shows its items according to the format below.
<img1> <img2> <img3> <img4>
<caption1> <caption1> <caption1> <caption1>
<img5> <img6> <img7> <img8>
<caption5> <caption6> <caption7> <caption8>
and so on...

You can use custom formatting options with the DataList or Repeater controls instead of a GridView. Check these examples for help :
http://csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html.
http://www.asp.net/web-forms/tutorials/data-access/displaying-data-with-the-datalist-and-repeater/formatting-the-datalist-and-repeater-based-upon-data-vb

Set AutoGenerateColumn property of gridview to false and then use <asp:TemplateField><ItemTemplate> under <Columns> section to add controls the way you like.

Related

Hide/ show 'Add new record' in telerik:RadGrid

So i have page contain telerik:RadGrid on top of the grid there Add new button i want when the user not allow to add new record to put visible =false
else visible =true i want to do it in code behind
All I can find on net is how to disable the button, and this not what I want I want - to hide/show it depend on user
I am assuming your grid's name as gridExample. gridExample.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false will help you in hiding or showing based on the user.
I've had this problem before too. I never found a RadGrid property where you can make the Add new record button invisible. The way I solved it was a little hackish. You can do this with CSS, or JQuery.
The name of the button is usually something like ctl00$ContentPlaceholder1$RadGrid1$ctl00$ctl02$ctl00$AddNewRecordButton. So I've used javascript/JQuery to hide it. The javascript would look like:
$('#ctl00$ContentPlaceholder1$RadGrid1$ctl00$ctl02$ctl00$AddNewRecordButton').hide();
You would need server-side (ASP) logic to put this code in your (client-side) JQuery page startup code.
For your page, you might need to change the name (above), if your grid is not named RadGrid1. To find the name of your control, you can view source, or use the DOM debugger (F12 in InternetExplorer) and find the text "Add new record".
You use call ShowAddNewRecordButton. Please ensure you call MasterTableView.Rebind depending on your logic.
RadGrid1.MasterTableView.CommandItemSettings
.ShowAddNewRecordButton = true;
RadGrid1.MasterTableView.Rebind();
Add <CommandItemSettings ShowAddNewRecordButton="false" /> inside the MasterTableView like below
<MasterTableView>
<CommandItemSettings ShowAddNewRecordButton="false" />
<Columns>
</Columns>
</MasterTableView>

How can I access custom Textbox attributes in ASP.Net?

I am using/abusing CSS classes and custom html attributes to provide default data to a set of textboxes. The code-front for this looks like the following (with some supporting javascript to handle checking/setting the default data when the field is blank):
<asp:TextBox ID="TXT_LenderName" class='defaultText' data-default='Institution Name' runat="server"></asp:TextBox>
This works.
I am working on the code-behind to process this form. I would like to be able to compare the value of the TXT_LenderName.Text to the value of the data-default attribute, but I haven't been able to find a way to get the value of a custom html attribute. Suggestions?
This is tested and worked
string customAttrDataDefault = TXT_LenderName.Attributes["data-default"];
txtpassword.Attributes.Add("value","Password value");
try this:
TXT_LenderName.Attributes["AttributeName"]= value;//here get or set the value.
If the control, like the TextBox control inherits from the System.Web.UI.WebControls.Control class then it should have an Attributes property which is a name value pair collection of the control's attributes.

Filtered Drop Down list items and search in ASP.NET

I have a drop down list and when user types something in the same, the drop down list must show the filtered options to be selected. I have done the code behind but filtering is pending.
<asp:DropDownList ID="AppraisersDpd" runat="server" Width="134px"
CssClass="dropdownpersonal textfont"
onselectedindexchanged="AppraisersDpd_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
The code behind is also there which is running:
AppraisersDpd.DataSource = apprblobj.FillAppraisers(); //fills Appraisers drop down
AppraisersDpd.DataTextField = "AppraiserName";
AppraisersDpd.DataValueField = "AppraiserId";
AppraisersDpd.DataBind();
can any one suggests me some clue? Should I use Combo box or I am going right?
This will require some Javascript to be implemented; as none of the ComboBox server-side events fire when you type something in a combo. I suggest you use a 3rd party ComboBox control that supports the "auto-complete" feature. The Ajax Toolkit ComboBox control may work out for you.

Sorting item template when programmatically add HeaderText

I have datagrid and inside this grid have template field. I add Header text progr. like this
gvData.HeaderRow.Cells(8).Text = "Hi"
But when I do this I can not sort this column when add SortExpression="Hi", i not have clickable header.
How can I do this
Tnx
I solve this with CType(gvData.HeaderRow.Cells(8).Controls(0), WebControls.LinkButton).Text

DropDownList DataValue as object

DataTextField="Name"
DataValueField="ID_ListGroupParIzm"
???? DataValueField2="ID_Point"
is it real to load 2 values from sqlDataSource in one DropDown list ? Get structure object from sqlDataSource ?
I can see only one way - making a new table to combine ID_Point and ID_ListGroupParIzm to one ID but that's really weird.
The only reason I can see for trying to do this is so that you can use javascript to affect two other objects on the page when something is selected.
If that is the case, I would strongly suggest using css classes instead and using jQuery (or another similar framework to select them from the dom.
eg.
<div id="ctl00_point" class="point item1">Content</div>
<div id="ctl00_listgrouppartzm" class="lgpartzm item1">Content</div>
<div id="ctl01_point" class="point item2">Content</div>
<div id="ctl01_listgrouppartzm" class="lgpartzm item2">Content</div>
Now rather than trying to store "point1|listgrouppartzm1" into the value of the drop down list and then parse it out, you only have to store "item1" and you have all the information you need to find those two divs.
In jQuery, you can get them both by
$(".item1")
or individually by
$(".item1.point")
$(".item1.lgpartzm")
You need to combine two fields before data-binding to the dropdownlist.
I think it's the only way to do it.

Resources