I have a gridview
<asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
<asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
<asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
<asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" />
<asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
<asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
<asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
<asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
<asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
<asp:BoundField DataField="RefundType" HeaderText="RefundType" />
in this gridview i want to add airlinepenality and ddlairlinepanelity to one column
how can i do that thanks in advance
You can create a template field and bind two fields like this.
<asp:TemplateField HeaderText="Airlinepenality" SortExpression="ddlAirlinePenality">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("AirlinePenality")+ " " + Eval("ddlAirlinePenality")%>' ></asp:Label>
</ItemTemplate>
you are using Bound field, we can merge two columns by TemplateField only, So better you can merge that two columns in your query,
try like below...
Query:
SELECT UnusedTicketAmount, ddlUnusedAmount,
cast(1.25 as varchar) + ' ' + cast(172813.99 as varchar) as AirlinePenality,
NetRefundProcess,ddlNetRefundProcess,RefundableCommission
ddlRefundableCommission,CouponRefunded,RefundType
Gridview
<asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
<asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
<asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
<asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
<asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
<asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
<asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
<asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
<asp:BoundField DataField="RefundType" HeaderText="RefundType" />
Suppose you want to merge last three columns of your grid then you can also use the below code:
protected void grdAirTicketList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[8].Visible = false;
e.Row.Cells[7].Visible = false;
e.Row.Cells[6].Attributes.Add("colspan", "3");
}
}
This means your column named 'CouponRefunded' and 'RefundType' will not be visible and 'ddlRefundableCommission' will be visible with colspan 3.
Related
I am trying to display the 7 days of the week inside GridView header so my code below shows how to get those days but I don't know how to put them in Gridview Header
with day of names of the week. About like image shows. I run ASP.NET with SQL SERVER EXPRESS database use sqldatasource connection to select all employees to a gridview.
foreach (DateTime selectedDateTime in Calendar1.SelectedDates)
{
Response.Write(selectedDateTime.ToShortDateString() + " <br/>");
}
You can create the columns in the GridView this way:
<asp:GridView ID="GridView1" runat="server" ShowHeader="true" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Monday" HeaderText="Monday" />
<asp:BoundField DataField="Thuesday" HeaderText="Thuesday" />
<asp:BoundField DataField="Wednesday" HeaderText="Wednesday" />
<asp:BoundField DataField="Thursday" HeaderText="Thursday" />
<asp:BoundField DataField="Friday" HeaderText="Friday" />
<asp:BoundField DataField="Saturday" HeaderText="Saturday" />
<asp:BoundField DataField="Sunday" HeaderText="Sunday" />
</Columns>
</asp:GridView>
If no data is expected in the days of the week columns, you could use TemplateFields:
<asp:GridView ID="GridView1" runat="server" ShowHeader="true" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:TemplateField HeaderText="Monday" />
<asp:TemplateField HeaderText="Thuesday" />
<asp:TemplateField HeaderText="Wednesday" />
<asp:TemplateField HeaderText="Thursday" />
<asp:TemplateField HeaderText="Friday" />
<asp:TemplateField HeaderText="Saturday" />
<asp:TemplateField HeaderText="Sunday" />
</Columns>
</asp:GridView>
I have the bottom Details view and it shows one detail on a single row is there any there any method that i could use do that i can show multiple detail view objects
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
AutoGenerateRows="False" EnableViewState="False"
DataKeyNames="questionID" DataSourceID="AllQuestions" AllowPaging="True">
<Fields>
<asp:BoundField DataField="SubjectName" HeaderText="SubjectName"
SortExpression="SubjectName" />
<asp:BoundField DataField="Chapter" HeaderText="Chapter"
SortExpression="Chapter" />
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="Section" />
<asp:BoundField DataField="questionID" HeaderText="questionID"
InsertVisible="False" ReadOnly="True" SortExpression="questionID" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="sectionID" HeaderText="sectionID"
SortExpression="sectionID" />
<asp:BoundField DataField="QuestionNo" HeaderText="QuestionNo"
SortExpression="QuestionNo" />
<asp:BoundField DataField="question" HeaderText="question"
SortExpression="question" />
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
<asp:BoundField DataField="D" HeaderText="D" SortExpression="D" />
<asp:BoundField DataField="correctAnswer" HeaderText="correctAnswer"
SortExpression="correctAnswer" />
<asp:BoundField DataField="explanation" HeaderText="explanation"
SortExpression="explanation" />
</Fields>
</asp:DetailsView>
Not that I know of.... DetailsView is meant for a single record. Use a GridView or Repeater or ListView for multiple records.
I want to hide a column in a gridview. I use the following code;
dgvTekleme.Columns[1].Visible = false;
but this does not work. (may be it does not work because of using that column in the code)
Is there any solution to hide a column in code-behind
you can do this manually.....
goto asp:gridview tag and in gridview tag set autogeneratecolumn="false"
if you don't want to display some column just don't write that column....
for example if you don't want to display prodId column just erase that line....
and write manually for displaying data like!!!!!!!!!!
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="ProdID" DataField="prodid" ReadOnly="true" />
<asp:BoundField HeaderText="ProdName" DataField="ProdName" />
<asp:BoundField HeaderText="Quantity" DataField="quantity" />
<asp:BoundField HeaderText="SupplierID" DataField="SupplierId" />
<asp:BoundField HeaderText="StockLvl" DataField="stocklevel" />
<asp:BoundField HeaderText="MinStockLvl" DataField="minstocklevel" />
<asp:BoundField HeaderText="CostPrice" DataField="costprice" />
<asp:BoundField HeaderText="SalesPrice" DataField="saleprice" />
<asp:BoundField HeaderText="Loc" DataField="location" />
<asp:BoundField HeaderText="ProdCode" DataField="prodtypecode" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
or you can check this link:
How to hide columns in an ASP.NET GridView with auto-generated columns?
How to set the Boolean value into GridView Check boxes in C#?
This is my code simply
static List<bool> bh = new List<bool>(6);
dt.Columns.Add("Hold");
dr["Hold"] = rem[x].Hold;
bh.Add(Convert.Toboolean((string)dr["Hold"]));
gridview codes
<Columns>
<asp:BoundField DataField="RemitID" HeaderText="RemitID" />
<asp:BoundField DataField="TransferedDate" HeaderText="TransferedDate" />
<asp:BoundField DataField="ValueDate" HeaderText="ValueDate" />
<asp:BoundField DataField="RemitterName" HeaderText="RemitterName" />
<asp:BoundField DataField="BenificiaryName" HeaderText="BenificiaryName" />
<asp:BoundField DataField="AccountNo" HeaderText="AccountNo" />
<asp:BoundField DataField="Reference" HeaderText="Reference" />
<asp:CheckBoxField DataField="Hold" HeaderText="Hold" />
<asp:CheckBoxField DataField="Reject" HeaderText="Reject" />
<asp:CheckBoxField DataField="Delete" HeaderText="Delete" />
</Columns>
here i am using List<> because have to add set of datas. No runtime errors are occur but checkboxes not showing the values.. Thank you !
i use this code .. but when the hyperlinks are longer then field size the gridview expands verticaly. i want the link below as like a paragraph . give me a solution
<asp:gridview id="titlesGrid" runat="server"
datasourceid="titles"
width=90% cellpadding=5 font-size="8pt"
autogeneratecolumns=false
headerstyle-backcolor="maroon"
headerstyle-forecolor="khaki"
headerstyle-font-bold
rowstyle-verticalalign="top">
<columns>
<asp:hyperlinkfield headertext="Title"
datatextfield="title"
datanavigateurlformatstring="title_details.aspx?titleid={0}"
datanavigateurlfields="title_id" />
<asp:boundfield headertext="Title ID"
datafield="title_id" />
<asp:boundfield headertext="Category"
datafield="type" />
<asp:boundfield headertext="Pub ID"
datafield="pub_id" />
<asp:boundfield headertext="Price"
datafield="price"
htmlencode=false
dataformatstring="{0:n2}"
itemstyle-horizontalalign="right" />
</columns>
</asp:gridview>
Have you tried using <ItemStyle Wrap="True" /> for <asp:hyperlinkfield /> ?