How to set the Boolean value into GridView Check boxes in C#? - asp.net

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 !

Related

asp:DetailsView shows one object per page can show multiple

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.

setting a commandname in gridview buttonfield

I have a button in my rows in a gridview and when clicking the button some code behind handles the button click. I want to pass a commandname paramater through with each button click, which is really just an order id. I'm wondering how I can set the commmand name for each button.
<Columns>
<asp:BoundField DataField="status" HeaderText="Status" HeaderStyle-HorizontalAlign="Left" SortExpression="status" />
<asp:BoundField DataField="orderid" HeaderText="Order ID" HeaderStyle-HorizontalAlign="Left" SortExpression="orderid" />
<asp:BoundField DataField="customer" HeaderText="Customer" HeaderStyle-HorizontalAlign="Left" SortExpression="customer" />
<asp:BoundField DataField="email" HeaderText="Email" HeaderStyle-HorizontalAlign="Left" SortExpression="email" />
<asp:BoundField DataField="createddate" HeaderText="Created Date" HeaderStyle-HorizontalAlign="Left" SortExpression="createddate" />
<asp:BoundField DataField="promocode" HeaderText="Promo Code" HeaderStyle-HorizontalAlign="Left" SortExpression="promocode" />
<asp:BoundField DataField="grandtotal" HeaderText="Grand Total" HeaderStyle-HorizontalAlign="Left" SortExpression="grandtotal" DataFormatString="{0:C}"/>
<asp:ButtonField Text="View" CommandName="6182" ButtonType="Button" />
</Columns>
As you can see abve the last column is the button that appears on each row and I've currently set it to 6182 - just as an example. What I really want to set it to is the orderid value...
How can I do that?
Thanks,
I'd probably go for something similar to this:
<asp:ButtonField Text="View" CommandName='<%# Eval("orderid") %>' ButtonType="Button" />
That should insert the orderid for the bound row into that field. If it doesn't work, convert the column into a TemplateField, add a button and do the same. Report back :-)

hiding a column in asp.net

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 merge two column in gridview

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.

hyperlink should come in multiline code not working

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 /> ?

Resources