I have gridview with itemtemplate columns and it generates extra tr in rendered html
i have set CellPadding="0" CellSpacing="0" and AutoGenerateColumns="false", but is doesn't help..
here is my gridview:
<asp:GridView ID="GridView1" GridLines="None" runat="server"
CellPadding="0" CellSpacing="0" ShowFooter="true"
AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="Grid_PageIndexChanging">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="0" width="100%"
class="table_sabcho">
</HeaderTemplate>
<ItemTemplate>
<tr id="sds">
<td><a href="show_item.aspx?id=<%# DataBinder.Eval (Container.DataItem, "id") %>">
<%# DataBinder.Eval(Container.DataItem, "number")%></a>
</td>
<td><%# DataBinder.Eval(Container.DataItem, "date","{0 :dd/MM/yyyy}")%>
</td>
<td><%# DataBinder.Eval(Container.DataItem, "Category")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "type_name")%>
</td>
<td style="padding-left: 0;"><%# getDoc((DataBinder.Eval(Container.DataItem, "id")).ToString())%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table> </FooterTemplate>
</asp:TemplateField>
</Columns>
here is how i databind grid:
protected void GetLastNewsGrid()
{
String query = "Select * from sample_view order by id desc";
DataSet lawdataset = SqlHelper.ExecuteDataset(connString, CommandType.Text, query);
GridView1.DataSource = lawdataset;
GridView1.DataBind();
}
here is rendered html :
<tr id="it is empty.." >
<td></td>
</tr>
<tr id="sds" >
<td> 4965/2/12 </td>
<td>24.12.2012 </td>
<td></td>
<td>dep </td>
<td style="padding-left: 0;"><a class="pdf_box" href="common/get_doc.aspx?docID=6900" ></a></td>
</tr>
Related
I currently have a DataList control, with the ItemTemplate and EditItemTemplate defined.
<asp:DataList ID="UserMatrixDataList" runat="server" RepeatColumns = "1" CellSpacing = "6" RepeatLayout="Table" BorderWidth="5">
<ItemTemplate>
<table class="table">
<col width="130">
<col width="800">
<tr>
<td >
<strong>Level</strong>
</td>
<td>
<asp:Label ID="lblLevel" runat="server" Text='<%# Eval("Level")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table class="table">
col width="130">
<col width="800">
<tr>
<td >
<strong>Level</strong>
</td>
<td>
<asp:Textbox ID="txtLevel" runat="server" Text='<%# Eval("Level")%>'></asp:Textbox>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:DataList>
After I do a Databind(), may I ask how can I set all records in the datalist to EditMode?
I am trying to change the background color on a row if the absolute value of an added column in a table is less than 8. I have tried several different ways, but the latest attempt, although seemingly close, does not perform as I expected.
<asp:ListView ID="ListView2" runat="server" >
<LayoutTemplate>
<table id="Table2" style="border:solid" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table runat="server" id="itemPlaceholderContainer" border="0" >
<tr id="Tr2" runat="server" style='<%# Eval("Alert") %>'>
<th id="Th1" runat="server">Date</th>
<th id="Th2" runat="server">Home</th>
<th id="Th3" runat="server">Score</th>
<th id="Th4" runat="server">Away</th>
<th id="Th5" runat="server">Score</th>
<th id="Th6" runat="server">Quarter</th>
<th id="Th7" runat="server">Link To Game</th>
<th id="Th8" runat="server"></th>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<AlternatingItemTemplate>
<tr style="">
<td style="border:solid">
<asp:Label Text='<%# Eval("Date") %>' runat="server" ID="DateLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName") %>' runat="server" ID="HighSchoolNameLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HomeTeamScore") %>' runat="server" ID="HomeTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName1") %>' runat="server" ID="HighSchoolName1Label2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("AwayTeamScore") %>' runat="server" ID="AwayTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("Quarter") %>' runat="server" ID="LabelQuarter" /></td>
<td style="border:solid" id="HomeAudioLink">
<a href="<%# Eval("AudioInternetLink") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink") %>' runat="server" ID="LabelHomeAudioLink" />
</a>
</td>
<td style="border:solid" id="AwayAudioLink">
<a href="<%# Eval("AudioInternetLink1") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink1") %>' runat="server" ID="LabelAwayAudioLink" />
</a>
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr id="Game" style="" runat="server" class="" >
<td style="border:solid">
<asp:Label Text='<%# Eval("Date") %>' runat="server" ID="DateLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName") %>' runat="server" ID="HighSchoolNameLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HomeTeamScore") %>' runat="server" ID="HomeTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("HighSchoolName1") %>' runat="server" ID="HighSchoolName1Label2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("AwayTeamScore") %>' runat="server" ID="AwayTeamScoreLabel2" /></td>
<td style="border:solid">
<asp:Label Text='<%# Eval("Quarter") %>' runat="server" ID="LabelQuarter" /></td>
<td style="border:solid" id="HomeAudioLink">
<a href="<%# Eval("AudioInternetLink") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink") %>' runat="server" ID="LabelHomeAudioLink" />
</a>
</td>
<td style="border:solid" id="AwayAudioLink">
<a href="<%# Eval("AudioInternetLink1") %>" target="_blank" >
<asp:Label Text='<%# Eval("AudioInternetLink1") %>' runat="server" ID="LabelAwayAudioLink" />
</a>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
And the C# code:
protected void ScheduleButton_Click(object sender, EventArgs e)
{
/**********************************************************************/
/* The code below will initialize the connection to the database. */
/* As the connection string to the SQL database is defined as conn, */
/* the open method from conn will connect to the database, and the */
/* cmd variable will call on the stored procedure GetSchedule. */
/**********************************************************************/
string strcon = WebConfigurationManager.ConnectionStrings["FollowingHSFootballConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strcon))
{
SqlCommand cmd = new SqlCommand("CurrentSchedScore", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
DataTable ScheduleTbl = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// Fill the partial DataSet into a partial DataTable.
da.Fill(ScheduleTbl);
ListView2.DataSource = ScheduleTbl;
ListView2.DataBind();
// Close Game Logic
ScheduleTbl.Columns.Add("Diff", typeof(int), "HomeTeamScore - AwayTeamScore");
ScheduleTbl.Columns.Add("Alert", typeof(string), "");
for (int i = 0; i < ScheduleTbl.Rows.Count; i++)
{
DataRow drST = ScheduleTbl.Rows[i];
if (Math.Abs((int)drST.ItemArray.GetValue(8)) <= 8)
{
drST.BeginEdit();
drST.ItemArray.SetValue("background-color:red", 9);
drST.AcceptChanges();
drST.EndEdit();
}
}
}
}
Where did I misunderstand how to update the last column?
I found that I had to use a javascript solution that worked.
#Class = ClassSchedDropDown.SelectedValue;
if (RegionSchedDropDown.SelectedValue == "")
{
for (int i = 1; i <= 8; i++)
{
SchedScoreDirect = "CurrentSchedScoreClassReg";
#Reg = i;
}
}
The SchedScoreDirect = "CurrentSchedScoreClassReg code will direct processing to send the red background to the appropriate row.
The data is displayed from database as follows using list view.I have a hyperlink in list View on click of which i need to set session with the id or datakey of the clicked item row.how can i get it?
<asp:ListView ID="lstvwResultInquiry" runat="server" DataKeyNames="inquiry_id"
onitemdatabound="ListView1_ItemDataBound"
onpagepropertieschanging="PagePropertiesChanging"
onitemcanceling="CancelListViewItem" onitemediting="EditListViewItem"
onselectedindexchanging="lstvwResultInquiry_SelectedIndexChanging" >
<LayoutTemplate >
<div id="rightnowIn">
<table class="gridview"cellpadding="5" cellspacing="5" >
<tr class="header">
<th width="140">Company</th>
<th width="220">Event</th>
<th width="125">Country</th>
<th width="125">Date</th>
<th width="100">Details</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
<tr id="Tr1" runat="server" align="center" >
<td colspan="2" align="left"><asp:Label ID="lblCount" runat="server"></asp:Label></td>
<td id="Td1" runat="server" style="" colspan="4">
<asp:DataPager class="mpart" ID="DataPager1" PageSize="15" runat="server" align="center">
<Fields>
<asp:NumericPagerField ButtonType="Link"ButtonCount="3" PreviousPageText="<<<" NextPageText=">>>" />
</Fields>
</asp:DataPager>
</td>
<td colspan="2" align="left"></td></tr></table>
</LayoutTemplate>
<ItemTemplate >
<tr class="itemTemplateTr" >
<td style="color: #403f3f; font-weight: bold;"><%# Eval("company")%></td>
<td><asp:Label ID="lblEvents" runat="server" ></asp:Label></td>
<td><%# Eval("country_name")%></td>
<td><%# Eval("date", "{0:dd-MM-yyyy}")%></td>
<% if (Session["session_log_id"] != null)
{ %>
<td class="command"><asp:HyperLink ID="btnEdit" runat="server" Text="View" commandName="view" cssclass="linkEditButton" Font-Underline="True"/</td
<%} %>
<td>
<asp:Button ID="buttReminder" runat="server" Visible="false" CssClass="reminderButton" CommandArgument='<%# Eval("inquiry_id")%>' OnClick="buttReminderInquiry_Click" BorderStyle="None" /></td> </tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="alternatingItem">
<td style="color: #403f3f; font-weight: bold;"><%# Eval("company")%></td>
<td><asp:Label ID="lblEvents" runat="server" ></asp:Label></td>
<td><%# Eval("country_name")%></td>
<td><%# Eval("date", "{0:dd-MM-yyyy}")%></td>
<% if (Session["session_log_id"] != null)
{ %>
<td class="command"><asp:HyperLink ID="btnEdit" runat="server" Text="View" cssclass="linkEditButton" Font-Underline="True" /></td>
<%} %>
<td>
<asp:Button ID="buttReminder" runat="server" Visible="false" CssClass="reminderButton" CommandArgument='<%# Eval("inquiry_id")%>' OnClick="buttReminderInquiry_Click" BorderStyle="None" /></td>
</tr></AlternatingItemTemplate>
<EmptyDataTemplate>
<div style="text-align:center;font-weight:bold">0 Results Founds</div>
</EmptyDataTemplate>
</asp:ListView>
Now I want to know the row index clicked on click of hyperlink.I want to set the session with the datakey on the selected row i.e clicked hyperlink.
select | Application No.
There are two columns in my listview(generated by following code) where 1st column is select link while other is simple column with header application number (header shown above):
<asp:ListView ID="ListBox1" runat ="server" AutoPostBack="True"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color: #336699; color: White;">
<th>Select</th>
<th>Application No.</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server" />
</td>
<td><%# Container.DataItem %></td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color: #336699; color: White;">
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
ForeColor="White" />
</td>
<td><%# Container.DataItem %></td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
now i want to display application number from string[] array. How i can do that plz help..?
//are you using datatable as datasource?, if so
var arr = new[] { "one", "two" };
var dt = new DataTable();
dt.Columns.Add("ApplicationNo", typeof(string));
var i = 0;
foreach (DataRow dr in dt.Rows)
{
dr["ApplicationNo"] = arr[i];
dt.AcceptChanges();
i++;
}
ListBox1.DataSource=dt;
ListBox1.DataBind();
Try this,
<asp:ListView ID="mylist" runat="server"
onselectedindexchanged="mylist_SelectedIndexChanged">
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color: #336699; color: White;">
<th>
Select
</th>
<th>
Application No.
</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton OnClick="lnkSelect_OnClick" ID="lnkSelect" Text="Select" CommandArgument='<%# Container.DataItem %>' CommandName="Select" runat="server" />
</td>
<td>
<%# Container.DataItem %>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color: #336699; color: White;">
<td>
<asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
ForeColor="White" />
</td>
<td>
<%# Container.DataItem %>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
IList<string> myList = new List<string>();
myList.Add("1");
myList.Add("3");
myList.Add("2");
myList.Add("4");
mylist.DataSource = myList;
mylist.DataBind();
OR
string[] myList = new string[] { "1","2","3" };
mylist.DataSource = myList;
mylist.DataBind();
protected void lnkSelect_OnClick(object sender, EventArgs e)
{
string val = ((System.Web.UI.WebControls.LinkButton)(sender)).CommandArgument;
}
I have a dynamic Listview which is bind to three different tables with one to many relations i.e. one table row may contain many rows in other table. When i run my application i get this output.
But i want to get Listview in this format although this image has been edited using Photshop.
Here is Listview HTML.
<asp:ListView runat="server" ID="LV_ViewQuestion" DataKeyNames="UID, Question_ID">
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No Surveys.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="SURVEY_TYPELabel" runat="server" Text='<%# Eval("Survey_Type")%>' />
</td>
<td>
<asp:Label ID="SURVEY_TITLELabel" runat="server" Text='<%# Eval("Survey_Title") %>' />
</td>
<td>
<asp:Label ID="Question_TextLabel" runat="server" Text='<%# Eval("Question_Text")%>' />
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Option_Text")%>' />
</td>
<td>
<asp:LinkButton runat="server" ID="lb_DelQuestion" Text="Delete" CommandArgument='<%# Eval("Question_ID")%>' CommandName="XDelQuestion" CssClass="GeneralInput" />
<asp:LinkButton runat="server" ID="lb_AddMoreQuest" Text="Add Question" CommandArgument='<%# Eval("UID")%>' CommandName="XAddAnotQuestion" CssClass="GeneralInput" />
<asp:LinkButton runat="server" ID="lb_Publish" Text="Publish" CommandArgument='<%# Eval("UID")%>' CommandName="XPublishSurvey" CssClass="GeneralInput" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" class="nobordered" style="width: 580px;">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">Type</th>
<th id="Th2" runat="server">Title</th>
<th id="Th6" runat="server">Question</th>
<th id="Th4" runat="server">Options</th>
<th id="Th3" runat="server" style="width: 200px;">Actions</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" ButtonCssClass="GeneralButton" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
You can accomplish this hiding the cells in the ItemDataBound event of the ListView. Your code should look like this:
first add three global properties in your page
string type = string.Empty;
string title = string.Empty;
string question = string.Empty;
Then add the OnItemDataBound event to your list view
protected void LV_ViewQuestion_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label SURVEY_TYPELabel = (Label)e.Item.FindControl("SURVEY_TYPELabel");
Label SURVEY_TITLELabel = (Label)e.Item.FindControl("SURVEY_TITLELabel");
Label Question_TextLabel = (Label)e.Item.FindControl("Question_TextLabel");
if (SURVEY_TYPELabel.Text == type && SURVEY_TITLELabel == title &&
Question_TextLabel == question)
{
SURVEY_TYPELabel.Visible = false;
SURVEY_TITLELabel.Visible = false;
Question_TextLabel.Visible = false;
// Do the same for all the other control in cells you need to hide
}
else
{
type = SURVEY_TYPELabel.Text;
title = SURVEY_TITLELabel.Text;
question = Question_TextLabel.Text;
}
}
}