What is up with my spacing here? When the labels contain text the spacing is fine but then they are empty they have white space between each label. Why is extra space being added when the labels contain empty text?
With text in labels (what I want it to look like):
With no text in labels (how I do not want it to look like):
On the C# code behind side:
// On page load
for (int i = 1; i < 10; i++)
{
string ID = i.ToString();
PopulateLastNameLabel(ID);
}
protected void PopulateLastNameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 70;
lbl.Height = 20;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Red;
lbl.ID = "lastname_" + ID;
pnlLastNameLabel.Controls.Add(lbl);
}
On the ASP.NET side:
<asp:Table ID="tblDisplayTable" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNumberLabel" runat="server" Width="80px"></asp:Panel>
</asp:TableCell>
<asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
<asp:Panel ID="pnlPrizeDropDownList" runat="server" Width="130px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlNickNameLabel" runat="server" Width="70px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNicknameTextBox" runat="server" Width="125px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlFirstNameLabel" runat="server" Width="70px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlLastNameLabel" runat="server" Width="70px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlEmailAddressLabel" runat="server" Width="140px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlAddButton" runat="server" Width="40px"></asp:Panel>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
If I understand you question correctly, you need the following css (remove height from code behind).
The problem each control is in own table cell, so they won't horizontal align properly. So you need to set height explicitly for each control.
<style type="text/css">
td div { margin-right: 5px; }
td div input {border: 1px solid #828282; height: 21px; }
td div span { height: 25px; line-height: 25px; }
</style>
<asp:Table ID="tblDisplayTable" runat="server" CellPadding="0" CellSpacing="0">
<asp:TableRow>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNumberLabel" runat="server" Width="80px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
<asp:Panel ID="pnlPrizeDropDownList" runat="server" Width="130px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlNickNameLabel" runat="server" Width="70px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNicknameTextBox" runat="server" Width="125px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlFirstNameLabel" runat="server" Width="70px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlLastNameLabel" runat="server" Width="70px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlEmailAddressLabel" runat="server" Width="140px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlAddButton" runat="server" Width="40px">
</asp:Panel>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
string ID = i.ToString();
TextBoxLabel(ID);
PopulatePrizeNicknameLabel(ID);
PopulateFirstNameLabel(ID);
PopulateLastNameLabel(ID);
}
}
protected void TextBoxLabel(string ID)
{
TextBox lbl = new TextBox();
lbl.Width = 65;
lbl.Text = "";
lbl.ID = "TextBox_" + ID;
lbl.Text = ID;
pnlNickNameLabel.Controls.Add(lbl);
}
protected void PopulatePrizeNicknameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 125;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Green;
lbl.ID = "PrizeNickname_" + ID;
lbl.Text = ID;
pnlPrizeNicknameTextBox.Controls.Add(lbl);
}
protected void PopulateLastNameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 70;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Red;
lbl.ID = "lastname_" + ID;
lbl.Text = ID;
pnlLastNameLabel.Controls.Add(lbl);
}
protected void PopulateFirstNameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 70;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Blue;
lbl.ID = "firstname_" + ID;
lbl.Text = ID;
pnlFirstNameLabel.Controls.Add(lbl);
}
I prefer creating controls one row at a time instead of one column at a time, but that is not OP.
Related
I can't to display file icons according to file extensions in asp.net GridView.
The structure of GridView is nested
The tutorial is Displays file icons in asp.net
The error is :
Object reference not set to an instance of an object
In this line of code-behind :
if (!String.IsNullOrEmpty(lnkDownload.Text))
My code below.
Can you help me?
Thank you in advance for any help, really appreciated.
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server"
AutoGenerateColumns="false" CssClass="mGrid" Width="700"
HorizontalAlign="Center">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img id="fileImage" runat="server" src="" />
<asp:HiddenField ID="HiddenField1"
runat="server" Value='<%# Eval("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download" ItemStyle-
HorizontalAlign="Justify">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" Text='<%#
Eval("Name") %>' CommandArgument=
'<%# Eval("FullName") %>' runat="server"
OnClick="lnkDownload_Click"
OnClientClick="if (!confirm('Confirm ?'))
return false;"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string root = #FilePath;
string folder = GridView2.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvOrders = (GridView)e.Row.FindControl("gvOrders");
Label gvLabel = (Label)e.Row.FindControl("gvLabel");
Label gvFolder = (Label)e.Row.FindControl("gvFolder");
DirectoryInfo directory = new DirectoryInfo(root + "/" + folder);
FileInfo[] fileInfo = directory.GetFiles("*.*",
SearchOption.AllDirectories);
fCount = directory.GetFiles("*.*",
SearchOption.AllDirectories).Length;
gvLabel.Text = fCount.ToString();
long size = 0;
foreach (string file in Directory.GetFiles(root + "/" + folder,
"*.*", SearchOption.AllDirectories))
{
size += new FileInfo(file).Length;
}
gvFolder.Text = Math.Round((double)size / (double)(1024 * 1024),
2).ToString() + " MB";
LinkButton lnkDownload =
(LinkButton)e.Row.FindControl("lnkDownload");
HiddenField hf = (HiddenField)e.Row.FindControl("HiddenField1");
if (!String.IsNullOrEmpty(lnkDownload.Text))
{
HtmlImage image = (HtmlImage)e.Row.FindControl("fileImage");
image.Attributes.Add("src", GetIconForFile(hf.Value));
}
gvOrders.DataSource = fileInfo;
gvOrders.DataBind();
}
}
private string GetIconForFile(string fileText)
{
string extension = Path.GetExtension(fileText);
extension = extension.Trim('.').ToLower();
return "~/fileicons/" + extension + ".png";
}
You have a Nested GridView Structure and gvOrders is your inner GridView. So, you've to get LinkButton from inner GridView's row as like:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gvOrders = (GridView)e.Row.FindControl("gvOrders");
foreach (GridViewRow row in gvOrders.Rows)
{
LinkButton lnkDownload = (LinkButton)row.FindControl("lnkDownload");
HiddenField hf = (HiddenField)row.FindControl("HiddenField1");
if (!String.IsNullOrEmpty(lnkDownload.Text))
{
//... some code
}
}
}
}
I need to display error if user selects "Other" Radio button and leaves it blank or enters wrong data in textbox. once user enters right data error goes away.
<asp:RadioButtonList ID="radyears" AutoPostBack="true" runat="server" Height="63px" Width="100px" OnSelectedIndexChanged="radyears_SelectedIndexChanged" Font-Names="Arial" Font-Size="12pt">
<asp:ListItem Selected="True" Value="15">15 Years</asp:ListItem>
<asp:ListItem Value="30">30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtother" runat="server" AutoPostBack="True" Font-Names="Arial" Font-Size="12pt" Width="150px" MaxLength="10"></asp:TextBox>
<asp:Label ID="lblothererror" runat="server" Font-Names="Arial" Font-Size="11pt" ForeColor="Red"></asp:Label>
Below is image showing how radiobutton shows with textbox and error message label next to textbox.
Here is image of radiobutton display
##### Here is my Try
if (radyears.SelectedValue == "Other")
{
if (String.IsNullOrEmpty(txtother.Text) || (!double.TryParse(txtother.Text, out years)))
{
lblothererror.Text = "Not Valid Input";
return;
}
else
{
lblothererror.Text = "valid number";
return;
}
Try this code :-
<asp:RadioButtonList ID="radyears" AutoPostBack="true" runat="server" Height="63px" Width="100px" Font-Names="Arial" Font-Size="12pt" OnSelectedIndexChanged="radyears_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="15">15 Years</asp:ListItem>
<asp:ListItem Value="30">30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtother" runat="server" AutoPostBack="True" Font-Names="Arial" Font-Size="12pt" Width="150px" MaxLength="10" OnTextChanged="txtother_TextChanged"></asp:TextBox>
<asp:Label ID="lblothererror" runat="server" Font-Names="Arial" Font-Size="11pt" ForeColor="Red"></asp:Label>
and in aspx.cs page
protected void radyears_SelectedIndexChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
lblothererror.Text = "Enter age in Textbox";
}
else
{
lblothererror.Text = "";
}
}
protected void txtother_TextChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
double years = 100;
if (String.IsNullOrEmpty(txtother.Text) || (Convert.ToInt32(txtother.Text) > years))
{
lblothererror.Text = "Invalid";
}
else
{
lblothererror.Text = "valid";
}
}
else
{
lblothererror.Text = "";
}
}
Try this
Here is c# code
protected void radyears_SelectedIndexChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
lblothererror.Text = "Enter value in Textbox please";
}
}
protected void txtother_TextChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
double years = 123;//Any Value
if (String.IsNullOrEmpty(txtother.Text) || (!double.TryParse(txtother.Text, out years)))
{
lblothererror.Text = "Not Valid Input";
return;
}
else
{
lblothererror.Text = "valid number";
return;
}
}
else
{
lblothererror.Text = "";
return;
}
}
and here it is
<asp:RadioButtonList ID="radyears" AutoPostBack="true" runat="server" Height="63px" Width="100px" OnSelectedIndexChanged="radyears_SelectedIndexChanged" Font-Names="Arial" Font-Size="12pt">
<asp:ListItem Selected="True" Value="15">15 Years</asp:ListItem>
<asp:ListItem Value="30">30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtother" runat="server" OnTextChanged="txtother_TextChanged" Font-Names="Arial" Font-Size="12pt" Width="150px" MaxLength="10"></asp:TextBox>
<asp:Label ID="lblothererror" runat="server" Font-Names="Arial" Font-Size="11pt" ForeColor="Red"></asp:Label>
I have a small problem with adding and deleting TableRow
I created a table in my code behind :
private void RemplirTab(){
Table1.Rows.Clear();
/*
* METHODE TO CREATE TABLE
*/
TableHeaderRow ligneEntete = new TableHeaderRow();
TableHeaderCell entete1 = new TableHeaderCell();
entete1.Text = "Identifiant";
TableHeaderCell entete2 = new TableHeaderCell();
entete2.Text = "Description";
TableHeaderCell entete3 = new TableHeaderCell();
entete3.Text = "Prix";
TableHeaderCell entete4 = new TableHeaderCell();
entete3.Text = "Action";
ligneEntete.Cells.Add(entete1);
ligneEntete.Cells.Add(entete2);
ligneEntete.Cells.Add(entete3);
ligneEntete.Cells.Add(entete4);
Table1.Rows.Add(ligneEntete);
foreach (Produit px in listeP)
{
TableRow r = new TableRow();
TableCell colId = new TableCell();
colId.Text = Convert.ToString(px.Id);
TableCell colDescription = new TableCell();
colDescription.Text = px.Description;
TableCell colPrix = new TableCell();
colPrix.Text = Convert.ToString(px.Prix);
TableCell colAction = new TableCell();
// colAction.Text = "<a href='~/PageListeTable.aspx?Id="+px.Id+"'>Supprimer<a>";
HyperLink lienSupr = new HyperLink();
// lienSupr.ID = "lienSupr";
lienSupr.Text = "Supprimer";
lienSupr.NavigateUrl = "~/PageListeTable.aspx?Id=" + px.Id;
colAction.Controls.Add(lienSupr);
r.Cells.Add(colId);
r.Cells.Add(colDescription);
r.Cells.Add(colPrix);
r.Cells.Add(colAction);
Table1.Rows.Add(r);
}
}
in my aspx page I put the code below :
<asp:Table ID="Table1" runat="server">
</asp:Table> <br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
<asp:Label ID="Label1" runat="server" Text="Id : "
AssociatedControlID="Id"></asp:Label>
<asp:TextBox ID="Id" runat="server" Width="167px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Champ obligatoir " ControlToValidate="Id">*</asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" runat="server" Text="Description :"
AssociatedControlID="Descrip"></asp:Label>
<asp:TextBox ID="Descrip" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Prix :"
AssociatedControlID="prix"></asp:Label>
<asp:TextBox ID="prix" runat="server" Width="165px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="Prix erroné " ControlToValidate="prix" MaximumValue="225"
MinimumValue="10" Type="Double">*</asp:RangeValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Ajouter" onclick="Button1_Click" />
</asp:Content>
in my Page_Load() I call the methode to create a Table :
protected void Page_Load(object sender, EventArgs e)
{
if (listeP == null)
{
listeP = new List<Produit>();
listeP.Add(new Produit(1, "ordi", 200));
Produit p = new Produit(2, "clavier", 20);
listeP.Add(p);
}
string pId = Request["Id"];
if (pId != null)
{
int id = Convert.ToInt32(pId);
int pos = listeP.IndexOf(new Produit(id,null,0));
if(pos!=-1)
listeP.RemoveAt(pos);
}
RemplirTab();
}
the problem is when I try to add an table row using the form the last Delete Link is called lienSupr.NavigateUrl = "~/PageListeTable.aspx?Id=" + px.Id; so the row having the last id is deleting and the new line is creating after
some one can help me to resolve this problem
I have a gridview in an update panel and it is working fine. However on the click of the edit button I want to open the edit form. But the edit button click is not working. When i debug it, the method is working fine however the page doesn't postback. I have tried using triggers but to no avail.
<asp:UpdatePanel ID="upnlgrid" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:GridView ID="gvGroupMaster" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanging="gvGroupMaster_SelectedIndexChanging" OnSelectedIndexChanged="gvGroupMaster_SelectedIndexChanged" OnRowDataBound="gvGroupMaster_RowDataBound" AllowSorting="true" OnPageIndexChanging="gvGroupMaster_PageIndexChanging" OnSorting="gvGroupMaster_Sorting"
ShowHeader="True" CssClass="tabledata" Width="100%" DataKeyNames="igroup_id">
<AlternatingRowStyle CssClass="pointer" />
<RowStyle CssClass="even pointer" />
<HeaderStyle CssClass="headings" />
<Columns>
<asp:TemplateField HeaderText="Sort Order" ItemStyle-CssClass="colmn1" SortExpression="isort_position" >
<ItemTemplate>
<%-- <asp:ImageButton ID="btnSort" OnClick="btnSortClick" imageurl="../images/order-sort-btnup.png" runat="server"></asp:ImageButton>--%>
<asp:Button ID="btnSort" class="sortord pointer" runat="server" OnClick="btnSortClick" ></asp:Button>
<asp:Button ID="btnSortDown" class="sortorddown pointer" runat="server" OnClick="btnSortDownClick"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group Name" SortExpression="strgroup_name" ItemStyle-CssClass="colmn2" >
<ItemTemplate>
<asp:Label ID="lblGroupName" runat="server"
Text='<%# Bind("strgroup_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Short Name" SortExpression="strgroup_sname" ItemStyle-CssClass="colmn3" >
<ItemTemplate>
<asp:Label ID="lblShortName" runat="server"
Text='<%# Bind("strgroup_sname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Under" SortExpression="iparent_id" ItemStyle-CssClass="colmn4">
<ItemTemplate>
<asp:Label ID="lblUnder" runat="server"
Text='<%# Bind("strunder") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nature Of Group" SortExpression="strnature_of_group" ItemStyle-CssClass="colmn5">
<ItemTemplate>
<asp:Label ID="lblNatureOfGroup" runat="server"
Text='<%# Bind("strnature_of_group") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Affect Gross Profit" SortExpression="straffect_gross_profits" ItemStyle-CssClass="colmn6">
<ItemTemplate>
<asp:Label ID="lblAffectGrossProfits" runat="server" Text='<%# Bind("straffect_gross_profits") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nett DrCr Report" SortExpression="strnett_drcr_report" ItemStyle-CssClass="colmn7">
<ItemTemplate>
<asp:Label ID="lblNettDrcrReport" runat="server"
Text='<%# Bind("strnett_drcr_report") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created By" SortExpression="icreated_by" ItemStyle-CssClass="colmn8">
<ItemTemplate>
<asp:Label ID="lblCreatedBy" runat="server"
Text='<%# Bind("strcreated_by") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created On" SortExpression="dtcreated_on" ItemStyle-CssClass="colmn9">
<ItemTemplate>
<asp:Label ID="lblCreatedOn" runat="server"
Text='<%# Bind("dtcreated_on") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Updated On" SortExpression="dtupdated_on" ItemStyle-CssClass="colmn10">
<ItemTemplate>
<asp:Label ID="lbLastUpdatedOn" runat="server"
Text='<%# Bind("dtupdated_on") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actions" ItemStyle-CssClass="colmn11">
<ItemTemplate>
<asp:Button id="btnInfo" runat="server" class="infoicon" Text='<%# Eval("igroup_id") %>' OnClick="infoclick"/>
<asp:Button id="btnEdit" runat="server" class="editicon" CausesValidation="false" Text='<%# Eval("igroup_id") %>' OnClick="editclick"/>
<asp:Button id="btnDelete" runat="server" class="deleteicon" Text='<%# Eval("igroup_id") %>' OnClick="deleteclick"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
codebehind for edit click
protected void editclick(object sender, EventArgs e)
{
try
{
//int rindex = (((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex;
Button EditButton = (Button)gvGroupMaster.Rows[(((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex].FindControl("btnEdit");
edit(EditButton.Text.ToString());
this.Session["edit"] = EditButton.Text.ToString();
}
catch
{
}
}
protected void edit(string editid)
{
try
{
GroupMasterClass gm = new GroupMasterClass();
CompanyMasterClass co = new CompanyMasterClass();
gm.igroup_id = Convert.ToInt32(editid);
ResultClass objres = gm.fn_GetGroupByIdForEdit();
if (objres.bStatus)
{
eslist<GroupMasterClass> OBJLIST = objres.objData as eslist<GroupMasterClass>;
if (OBJLIST.Count > 0)
{
co.strcompany_code = Request.Cookies["userinfo"]["companycode"].ToString();
ResultClass objress = co.fn_GetNameNumberStyle();
if (objress.bStatus)
{
eslist<CompanyMasterClass> OBJLISTS = objress.objData as eslist<CompanyMasterClass>;
if (OBJLISTS.Count > 0)
{
addfrm.Visible = true;
gridmain.Visible = false;
if (OBJLISTS[0].strname_style.ToString() == "PC")
{
txtGroupName.Text = misc.ToTitleCase(OBJLIST[0].strgroup_name);
txtGroupSname.Text = misc.ToTitleCase(OBJLIST[0].strgroup_sname);
}
if (OBJLISTS[0].strname_style.ToString() == "UC")
{
txtGroupName.Text = (OBJLIST[0].strgroup_name).ToUpper();
txtGroupSname.Text = (OBJLIST[0].strgroup_sname).ToUpper();
txtGroupName.Style.Add("text-transform", "uppercase");
txtGroupSname.Style.Add("text-transform", "uppercase");
}
if (OBJLISTS[0].strname_style.ToString() == "UG")
{
txtGroupName.Text = (OBJLIST[0].strgroup_name).ToUpper();
txtGroupSname.Text = (OBJLIST[0].strgroup_sname).ToUpper();
}
}
}
txtUnder.Text = OBJLIST[0].strunder;
txtNotes.Text = OBJLIST[0].strnotes;
for (int i = 0; i < OBJLIST.Count; i++)
{
CompanyMasterClass cm = new CompanyMasterClass();
string p = OBJLIST[0].strcompany_code.ToString();
string t = string.Empty;
string code = string.Empty;
int count = 0;
string[] availcompanycode = p.Split(',');
foreach (string k in availcompanycode)
{
t = k.ToString();
code += "'" + t.ToString() + "'" + ",";
count++;
}
cm.strcompany_code = code.TrimEnd(',');
ResultClass objrest = cm.fn_GetCompanyListByCompanycode();
if (objres.bStatus)
{
eslist<CompanyMasterClass> OBJLISTS = objrest.objData as eslist<CompanyMasterClass>;
if (OBJLISTS.Count > 0)
{
// listboxsource.Items.Clear();
listboxdestination.DataTextField = "strcompany_name";
listboxdestination.DataValueField = "strcompany_code";
listboxdestination.DataSource = OBJLISTS;
listboxdestination.DataBind();
}
}
ListItem itemnature = new ListItem();
if (OBJLIST[i].strnature_of_group == "A")
itemnature.Text = "Assets";
else if (OBJLIST[i].strnature_of_group == "E")
itemnature.Text = "Expenses";
else if (OBJLIST[i].strnature_of_group == "I")
itemnature.Text = "Income";
else if (OBJLIST[i].strnature_of_group == "L")
itemnature.Text = "Liabilities";
// itemnature.Value = OBJLIST[i].igroup_id.ToString();
ddlNature.Items.Add(itemnature);
ListItem itemaffects = new ListItem();
if (OBJLIST[i].straffect_gross_profits == "N")
itemaffects.Text = "No";
else if (OBJLIST[i].straffect_gross_profits == "Y")
itemaffects.Text = "Yes";
//itemaffects.Value = OBJLIST[i].igroup_id.ToString();
ddlGrossProfit.Items.Add(itemaffects);
ListItem itemnett = new ListItem();
if (OBJLIST[i].strnett_drcr_report == "N")
itemnett.Text = "No";
else if (OBJLIST[i].strnett_drcr_report == "Y")
itemnett.Text = "Yes";
// itemnett.Value = OBJLIST[i].igroup_id.ToString();
ddlNett.Items.Add(itemnett);
ListItem itemlock = new ListItem();
if (OBJLIST[i].strlock_status == "N")
itemlock.Text = "No";
else if (OBJLIST[i].strlock_status == "Y")
itemlock.Text = "Yes";
// itemnett.Value = OBJLIST[i].igroup_id.ToString();
ddlNett.Items.Add(itemlock);
}
}
}
}
catch
{
}
}
Any ideas?
Thanks,
Try using Button editbtn = (Button)sender; Rather than Button EditButton = (Button)gvGroupMaster.Rows[(((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex].FindControl("btnEdit");
I have a datalist
<asp:DataList ID="dlstImage" runat="server" RepeatDirection="Horizontal" RepeatColumns="5"
CellSpacing="8">
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
OnCommand="Select_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index") %>' /><br />
<asp:Label ID="lbl" runat="server" Text="Figure"></asp:Label><%# dlstImage.Items.Count + 1%>
</ItemTemplate>
</asp:DataList>
In which i am binding the image after uploading through uplodify upload, now i have one more datalist
and two btn up and down,
<asp:ImageButton ID="ibtnMoveUp" runat="server" ImageUrl="~/App_Themes/Default/Images/moveup.bmp"
Style="height: 16px" ToolTip="MoveUp The Item" />
<asp:ImageButton ID="ibtnMoveDown" runat="server" ImageUrl="~/App_Themes/Default/Images/movedown.bmp"
ToolTip="MoveDown The Item" />
<asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
RepeatColumns="5" CellSpacing="8">
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" /><br />
<asp:Label ID="lbl" runat="server" Text="Figure"></asp:Label><%# dlstImage.Items.Count + 1%>
</ItemTemplate>
</asp:DataList>
My both datalist is in the same webuser control, datalist1 and datalist2 and I have 2 btn up and down, when i select one image from datalist1 and click on down btn then the selected image should move to datalist2. How to do that? someone please help me,
You need to handle the ItemCommand event of one DataList in which you have to copy the selected data (image) into another dataSource of two DataList and remove that item from the datasource of one DataList.
Markup:
<asp:DataList
ID="DataList1"
runat="server"
OnItemCommand="PerformMove"
>
<ItemTemplate>
<br /><%#Eval("Text") %>
<asp:Button ID="btn1"
runat="server"
Text="Move"
CommandName="cmd"
CommandArgument='<%#Eval("Text") %>'
/>
</ItemTemplate>
</asp:DataList>
<asp:DataList ID="DataList2" runat="server">
<ItemTemplate>
<br /><%#Eval("Text") %>
</ItemTemplate>
</asp:DataList>
Code-behind (.cs)
public class Data
{
public string Text { get; set; }
public override int GetHashCode()
{
return Text.GetHashCode();
}
public override bool Equals(object obj)
{
return GetHashCode() == obj.GetHashCode();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Data> list1 = new List<Data >()
{
new Data() { Text="One"},
new Data() { Text="Two"},
new Data() { Text="Three"},
};
List<Data> list2 = new List<Data>();
Session["list1"] = list1;
Session["list2"] = list2;
DataList1.DataSource = Session["list1"];
DataList1.DataBind();
DataList2.DataSource = Session["list2"];
DataList2.DataBind();
}
}
protected void PerformMove(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "cmd")
{
List<Data> list1 = Session["list1"] as List<Data>;
List<Data> list2 = Session["list2"] as List<Data>;
list1.Remove(new Data() { Text=e.CommandArgument.ToString() });
list2.Add(new Data() { Text = e.CommandArgument.ToString() });
DataList1.DataSource = Session["list1"];
DataList1.DataBind();
DataList2.DataSource = Session["list2"];
DataList2.DataBind();
}
}
I am using this code and its working well for me.
ArrayList ImgArry = new ArrayList();
path = objGetBaseCase.GetImages(TotImgIds);
ImgArry.Add(SelImgId);
ImgArry.Add(SelImgpath);//image name
ImgArry.Add(SelImgName);//image path
//path.Remove(ImgArry);
List<ArrayList> t = new List<ArrayList>();
if (newpath.Count > 0)
t = newpath;
t.Add(ImgArry);
newpath = t;
for (int i = 0; i < newpath.Count; i++)
{
ArrayList alst = newpath[i];
newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
dlstSelectedImages.DataSource = newtb;
DataBind();
path = objGetBaseCase.GetImages(TotImgIds);
for (int i = 0; i < path.Count; i++)
{
ArrayList alst = path[i];
tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
dlstImage.DataSource = tb;
DataBind();