顯示具有 Post 標籤的文章。 顯示所有文章
顯示具有 Post 標籤的文章。 顯示所有文章

2014年7月13日 星期日

[RESOLVED] displaying label values in multiline text from gridview


i got 1 gridview which has hyperlink in one column, wen the user clicks the link he will be directed to another page where the details of particular row will be displayed using individual labels. In those labels one of the label must be multilined for me
coz the text will be too long...


Please help me how to get that .


aspx page of label




Hi,


Just go through this post once: http://forums.asp.net/t/1323030.aspx



su88rao






nt useful... any othr solution ?




This problem could be because of absolute sizing or positioning of the label. don't specify the size of label and don't wrap it in absolutely sized container like panel and it will work fine.



i got the solution... by adding style="word-wrap:break-word;" to label and removing the height property of label can achieve tht 




<asp:Label ID="LblDescription" runat="server"
Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" ForeColor="#0061C1" Height="16px"
Width="97px" BorderColor="#0061C1"
BorderWidth="1px" style="word-wrap:break-word;" BackColor="White"></asp:Label>

[RESOLVED] How to create time countdown in datalist or gridview


Hi, I'm trying to make public auction list. And I need time countdown for every row in datalist or gridview. How do I create time countdown in datalist or gridview using Asp.Net/C#?




Have a look at this link,


How to display a timer countdown inside my Gridview:

http://forums.asp.net/t/1743407.aspx/1



Thanks sridhar_rs. I solved my problem.


.aspx




























codebehind


protected void Timer1_Tick(object sender, EventArgs e)
{

foreach (GridViewRow item in GridView1.Rows)
{
var label2 = item.FindControl("Label2") as Label;

var label3 = item.FindControl("Label3") as Label;
var time2 = DateTime.Parse(label3.Text);
label.Text = (time2 - DateTime.Now).Days + " Day " + (time2 - DateTime.Now).Hours + " Hours " + (time2 - DateTime.Now).Minutes + " Minutes " + (time2 - DateTime.Now).Seconds + " Seconds";
}

}




[RESOLVED] Detailsview null value


I want to check the value in Date Shipped. If there isn't anything in it, it won't allow the user to move on to the next page. I created a Session to check, but it never has a null value. I'm not sure why.


protected void Page_Load(object sender, EventArgs e)
{
lblError.Visible = false;
ShippingError.Visible = false;
CanceledError.Visible = false;
dvAddress.Visible = false;
dvCustomer.Visible = false;

}
protected void btnPacking_Click(object sender, EventArgs e)
{
Session["OrderID"] = dvOrder.SelectedValue;

if (Session["OrderID"] != null)
{
if (Session["Shipped"] != null)
{
Response.Redirect("~/PackageManagement/Packing2.aspx");
}
else
{
ShippingError.Visible = true;
}
}

else
{
lblError.Visible = true;
}
}

protected void dvOrder_DataBound(object sender, EventArgs e)
{


if (dvOrder.SelectedValue != null)
{
Label AddressID = dvOrder.FindControl("lblAddressID") as Label;
Address.Text = AddressID.Text;
Session["Address1"] = AddressID.Text;

if (dvOrder.CurrentMode == DetailsViewMode.ReadOnly)
{
Label Shipped = dvOrder.FindControl("lblShipped") as Label;
Session["Shipped"] = Shipped.Text;


}
dvAddress.Visible = true;
dvAddress.DataBind();
}
else
{
dvAddress.Visible = false;
}

}

    











































































Maybe you need to check for empty string instead. Or use the string isnullorempty().



Try as:


protected void btnPacking_Click(object sender, EventArgs e)
{
Session["OrderID"] = dvOrder.SelectedValue;

if (!string.IsNullOrEmpty(Session["OrderID"] as string))
{
if (!string.IsNullOrEmpty(Session["Shipped"] as string))
{
Response.Redirect("~/PackageManagement/Packing2.aspx");
}
else
{
ShippingError.Visible = true;
}
}

else
{
lblError.Visible = true;
}
}

Make sure each time databound you have to clear session values, for eg assign String.Empty in Session variable




 



Thank you! That worked (although I switched it to being empty).


Here's the code:



protected void Page_Load(object sender, EventArgs e)
{
lblError.Visible = false;
ShippingError.Visible = false;
CanceledError.Visible = false;
dvAddress.Visible = false;
dvCustomer.Visible = false;

}
protected void btnPacking_Click(object sender, EventArgs e)
{
Session["OrderID"] = dvOrder.SelectedValue;

if (Session["OrderID"] != null)
{
if (string.IsNullOrEmpty(Session["Shipped"] as string))
{
ShippingError.Visible = false;
Response.Redirect("~/PackageManagement/Packing2.aspx");
}
else
{
ShippingError.Visible = true;
}
}

else
{
lblError.Visible = true;
}
}

protected void dvOrder_DataBound(object sender, EventArgs e)
{
Session["Address1"] = null;
Session["Shipped"] = null;

if (dvOrder.SelectedValue != null)
{
Label AddressID = dvOrder.FindControl("lblAddressID") as Label;
Address.Text = AddressID.Text;
Session["Address1"] = AddressID.Text;

if (dvOrder.CurrentMode == DetailsViewMode.ReadOnly)
{
Label Shipped = dvOrder.FindControl("lblShipped") as Label;

if (Shipped != null)
{
Session["Shipped"] = Shipped.Text;
}
}
dvAddress.Visible = true;
dvAddress.DataBind();
}
else
{
dvAddress.Visible = false;
}

}







[RESOLVED] Line up drop down menu items?


Hi,


Using the code below I am populating a drop down menu but the text does not line up. Is there a way so that when the drop down loads that the City part is all in line? Currently the city part can be more to left or more to the right depending on the length
of the column before it? Thanks!


While reader.Read
customers.Add(reader("Provider Last Name (Legal Name)").ToString + ", " + reader("Provider First Name").ToString + " " + reader("Provider Business Mailing Address City Name").ToString + ", " + reader("Provider Business Mailing Address State Name").ToString + " " + reader("Provider Business Mailing Address Postal Code").ToString)

End While



I've created some similar functionality in the past for aligning items within Dropdowns that leverages the empty character (ALT+255) to create spaces within drop-downs that are recognized within


It uses some of the available padding within the String formatting function to allocate exactly how many characters you want to use for a specific field and then has an additional function to replace those spaces with the "invisible character" : 


string FormatForDropDown(string s, int length)
{
//Builds a string
StringBuilder sb = new StringBuilder();
//Iterates through and replaces the empty values with the empty character (not a space)
for (int i = 0; i < length; i++)
{
sb.Append((i < s.Length) ? s[i].ToString() : " ");
}
//Outputs the string
return sb.ToString();
}

and as far as actually adding the actual entry, it should be used as such : 


//Example of the item you would add to your Drop-down list
String.Format("{0,24} | {1,12} | {2,24}", FormatForDropDown(valueA, 24), FormatForDropDown(valueB, 12), FormatForDropDown(valueC, 24));

(Warning : This is old code)







Since you are using Visual Basic, it may look something like this : 


Public Function FormatForDropDown(ByVal s As String, ByVal length As Integer) As String
Dim sb = New StringBuilder()
For i As Integer = 0 To length
sb.Append(If(i < s.Length, s(i).ToString(), " "))
Next
Return sb.ToString()
End Function

and


'String to Add'
Dim entry = String.Format("{0,24} | {1,24} | {2,24} | {3,24} | {4, 24}",reader("Provider Last Name (Legal Name)").ToString(),reader("Provider Business Mailing Address City Name").ToString(), reader("Provider First Name").ToString(),reader("Provider Business Mailing Address State Name").ToString(), reader("Provider Business Mailing Address Postal Code").ToString()
'Add the entry'
customers.Add(entry)

Alternatively, you could simply replace the strings of spaces that you are using with the invisible character " " as mentioned : 


While reader.Read
customers.Add(reader("Provider Last Name (Legal Name)").ToString() + ", " + reader("Provider First Name").ToString + "          " + reader("Provider Business Mailing Address City Name").ToString() + ", " + reader("Provider Business Mailing Address State Name").ToString() + "  " + reader("Provider Business Mailing Address Postal Code").ToString())
End While

I attempted to replace them in the code above however it may not have worked properly. It's just important to note that all of the spaces that you see above within your strings are not actual spaces but the invisible character (ALT+255).







Thanks, this seems to be close to what i need, proglem is some of the last names have a "-" so it throws off the alignment. Thanks for your help with this. Maybe can it be a set width so its like an excel sheet where its just like a straight line between
with a set length?


               JOHNSON |                    AJITA |                     BEAR |                       DE |                197013036


               JOHNSON-Smith |                    AJITA |                     BEAR |                       DE |                197013036


 


[RESOLVED] Make DataCell Content link and open that link in a new window


Hi,


I have already made datagrid cell content link and open that link in a new window, but the problem is that the parent window content disappears and only "[object]" is written on the parent page after click on the link. I want that the Parent page must remains
there and when i click on the link the it opens in a new window as popup.


I have tried the following code


   runat="server"/>


Please correct me if any mistake or tell me some alternate way to do this


Thanks & Regards


Muhammad Arsalan Akhtar



Simply set target="_blank" and use DataNavigateUrlFormatString


    DataNavigateUrlFormatString="LoadBalance.aspx?EmbossLine={0}"
DataTextField="vchrEmbossLine" HeaderText="Emboss Line" Target="_blank" />





your code modify: -



Target="_blank"  runat="server"/>



I have tried this earlier but this will open a new tab, I want to open it as a popup in new window


Thanks for reply ,


plz help me 


Regards 


Muhammad Arsalan Akhtar




Target="_blank"  runat="server"/>


Except hyperlink use anchor tag



adfadfsa


It will work


hyper link only navigate in other tab so best use is that as tag


& you want to use server side you can use make set attribute as
runat="server" id="anchor1"




ars88


if using


'<%#Eval("FieldNameInDataBase")%>'


if link button using



 




Thanks buddy


Tell me one thing that can i use  <%#Eval("FieldNameindatabase")%> in window.open function


Plz reply






Dear,


 


of course you can use like


window.open('<%#Eval("FieldNameindatabase")%>')



SomeOne please help how to bind eval in window.open


Regards 


Muhammad Arsalan Akhtar



Use LinkButton



Set OnClientClick property from RowDataBound Event


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = e.Row.FindControl("LinkButton1") as LinkButton;
string vchrEmbossLine=Convert.ToString(DataBinder.Eval(e.Row.DataItem,"vchrEmbossLine"));
lb.OnClientClick = string.Format("window.open('LoadBalance.aspx?EmbossLine={0}',null,'width=800,height=800');", vchrEmbossLine);
}
}









Thanks every one for reply


Regards 


Muhammad Arsalan Akhtar


[RESOLVED] Exporting datalist and gridview to excel


Hello Experts,


I am having one datalist and gridview within datalist control. I need to export both of them as report in excel sheet. Like below


sr.  Class  CreatedDate ModifiedDate


1     Class1   25/5/2013   25/5/2013


Students


Sr.  Name Address Bdate


1    Abc    test add  25/5/1990


2    DEF   test add 2  25/3/1991


sr.  Class  CreatedDate ModifiedDate


2     Class2   25/6/2013   25/6/2013


Students


Sr.  Name Address Bdate


1    Abc2    test add22  25/5/1990


2    DEF2   test add 22  25/3/1991


and so on.....


Here the class display is datalist and student display is gridview.


Please suggest how to achive that?


Thank you.




Refer bellow url


http://www.aspsnippets.com/Articles/Export-GridView-To-WordExcelPDFCSV-in-ASP.Net.aspx



Hi,


Please try to refer to the following code about export data to excel (use the gridview as an example):


protected void fillGrid()
{
string str = "SELECT [UNo], [EmpName], [Age],
convert(char,[dob],103) dob FROM [tbl_EmpDetails]";

myConnection = new SqlConnection(conn);
myConnection.Open();
myCommand = new SqlCommand(str, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataTable();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet);
GridView1.DataSource = myDataSet;
GridView1.DataBind();
ViewState["dtList"] = myDataSet;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillGrid();
}
}

Now, after binding a Gridview, data is ready to get exported to an Excel file. Click on a button named Export to Excel. Used FileInfo to get the information related to the file.


FileInfo FI = new FileInfo(Path);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
DataGrid DataGrd = new DataGrid();
DataGrd.DataSource = dt1;
DataGrd.DataBind();

DataGrd.RenderControl(htmlWrite);
string directory = Path.Substring(0, Path.LastIndexOf("\\"));// GetDirectory(Path);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

System.IO.StreamWriter vw = new System.IO.StreamWriter(Path, true);
stringWriter.ToString().Normalize();
vw.Write(stringWriter.ToString());
vw.Flush();
vw.Close();
WriteAttachment(FI.Name, "application/vnd.ms-excel", stringWriter.ToString());

The above code uses a WriteAttachment function which pushes the attachment to the user in the Response object. The following code shows the implementation of WriteAttachment:


public static void WriteAttachment(string FileName, string FileType, string content)
{
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.ContentType = FileType;
Response.Write(content);
Response.End();
}

Hope it can help you.


Best Regards,

Amy Peng 


[RESOLVED] When going to previous page button disappears?


 



Hi,


I have a custom back button and when clicked it goes to the previous page but a button is missing and the size of other items is changed. Has anyone come accross this behavior? Thanks!


 



NM I redid the project using master pages and it working now



Hi,


I am very glad that you have solved your problem by yourself.


If you have any other problem, welcome to post it in the asp.net forums.


Best Regards,

Amy Peng 


[RESOLVED] Alphabetic Paging


Hi, Could you please help me on the issue of using the ASCII value of Georgian language characters. How can I change the english alphabet? I cannot retrive data since my contact list is in Georgian language. Here is the code:


public partial class alfabet : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["CurrentAlphabet"] = "ALL";
this.GenerateAlphabets();
this.BindDataList();
}
}

public class Alphabet
{
private string _value;
private bool _isNotSelected;

public string Value
{
get
{
return _value;
}
set
{
_value = value;
}
}

public bool isNotSelected
{
get
{
return _isNotSelected;
}
set
{
_isNotSelected = value;
}
}
}

private void GenerateAlphabets()
{
List alphabets = new List();
Alphabet alphabet = new Alphabet();
alphabet.Value = "ALL";
alphabet.isNotSelected = !alphabet.Value
.Equals(ViewState["CurrentAlphabet"]);
alphabets.Add(alphabet);
for (int i = 65; i <= 90; i++)
{
alphabet = new Alphabet();
alphabet.Value = Char.ConvertFromUtf32(i);
alphabet.isNotSelected = !alphabet.Value
.Equals(ViewState["CurrentAlphabet"]);
alphabets.Add(alphabet);
}
rptAlphabets.DataSource = alphabets;
rptAlphabets.DataBind();
}

private void BindDataList()
{
string conStr = ConfigurationManager
.ConnectionStrings["CompanyInfoEventsConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand("spx_GetContacts");
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Alphabet", ViewState["CurrentAlphabet"]);
con.Open();
dlContacts.DataSource = cmd.ExecuteReader();
dlContacts.DataBind();
con.Close();

if (ViewState["CurrentAlphabet"].ToString().Equals("ALL"))
lblView.Text = "all Contacts.";
else
lblView.Text = "Contacts whose name starts with "
+ ViewState["CurrentAlphabet"].ToString();
}

protected void Alphabet_Click(object sender, EventArgs e)
{
LinkButton lnkAlphabet = (LinkButton)sender;
ViewState["CurrentAlphabet"] = lnkAlphabet.Text;
this.GenerateAlphabets();
this.BindDataList();
}



}







Hi,


The ASCII value of the alphabets A-Z is 65 - 90 same way for Georgian language you need to set appropriate value.


#The ASCll Table:

http://www.asciitable.com/ . 


And I think this article may help you:

http://www.c-sharpcorner.com/uploadfile/satyapriyanayak/alphabetic-paging-using-gridview-control/ .


Best Regards,

Amy Peng 



[RESOLVED] Set MSChart AxixX.Minimum To DateTime


Dear All,


I am binding DateTime values to Chart Control. Everything is working fine. But I want set Minimum And Maximum of AxisX to DateTime value. like


Chart1.ChartAreas[0].AxisX.Minimum=DateTime.Now;

All though Minimum accepts only double value. How I achieve this one. Any suggestion is most valueble in for this post.


Thanks in advance.





Hi,


You can use the DateTime.ToOADate which returns double value.


For more information, please try to refer to the following thread:

http://stackoverflow.com/questions/9790831/having-issues-with-plotting-polar-data-on-a-datetime-x-axis.


#DateTime.ToOADate:

http://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx


Hope it can help you.


Best Regards,

Amy Peng 


[RESOLVED] calling Checkbox checked Event


I've a repeater and in repeater i've check box list..wheck is generated dynamically.


How i can call check box checked Even


here is code








<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:

<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]






<%-- --%>
runat="server">









Set cbl Autopostback="true"


CheckedChanged event is for CheckBox instead CheckBoxList


CheckBoxList is using SelectedIndexChanged


This sample for CheckBox


    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
RepeaterItem ri = (RepeaterItem)cb.NamingContainer;
HiddenField hdngrpOpid = (HiddenField)ri.FindControl("hdngrpOpid");
int idx = ri.ItemIndex;




}












<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:

<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]






<%-- --%>
runat="server" AutoPostBack="true" onselectedindexchanged="cbxControl_SelectedIndexChanged" >





On Code Behind
protected void cbxControl__SelectedIndexChanged(object sender, EventArgs e)
{

}


[RESOLVED] GridView column is hidden when export to excel exlcude the hidden column


I have a gridview, some of column is hidden but when i export to excel, in excel it still show the hidden column. May i know how to do it??


below is my sample script in App_Code:


public class GridViewExportUtil

{



    public static void Export(string fileName, GridView gv)

    {

        HttpContext.Current.Response.Clear();

        HttpContext.Current.Response.ClearContent();

        HttpContext.Current.Response.ClearHeaders();

        HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));



         using (StringWriter sw = new StringWriter())

        {

            using (HtmlTextWriter htw = new HtmlTextWriter(sw))

            {

                Table table = new Table();




                if (gv.HeaderRow != null)

                {

                    GridViewExportUtil.PrepareControlForExport(gv.HeaderRow);

                    table.Rows.Add(gv.HeaderRow);

                }



                foreach (GridViewRow row in gv.Rows)

                {

                    GridViewExportUtil.PrepareControlForExport(row);

                    table.Rows.Add(row);

                    

                }



                if (gv.FooterRow != null)

                {

                    GridViewExportUtil.PrepareControlForExport(gv.FooterRow);

                    table.Rows.Add(gv.FooterRow);

                }



                table.RenderControl(htw);



                HttpContext.Current.Response.Write(sw.ToString());

                HttpContext.Current.Response.Flush();

                HttpContext.Current.Response.Close();

                HttpContext.Current.Response.End();

            }

        }

    }



    private static void PrepareControlForExport(Control control)

    {

        for (int i = 0; i < control.Controls.Count; i++)

        {

            Control current = control.Controls[i];

            if (current is LinkButton)

            {

                control.Controls.Remove(current);

                control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));

            }

            else if (current is ImageButton)

            {

                control.Controls.Remove(current);

                control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));

            }

            else if (current is HyperLink)

            {

                control.Controls.Remove(current);

                control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));

            }

            else if (current is DropDownList)

            {

                control.Controls.Remove(current);

                control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));

            }

            else if (current is CheckBox)

            {

                control.Controls.Remove(current);

                control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));

            }

            else if (current.Visible == false)

            {

                control.Controls.Remove(current);

            }

            if (current.HasControls())

            {

                GridViewExportUtil.PrepareControlForExport(current);

            }

        }

    }



Maybe you can do like this


GridView1.AllowSorting = false;
GridView1.Columns[2].Visible = false;
//export process
GridView1.Visible = true;
GridView1.AllowSorting = true;









oned_gk



Maybe you can do like this
GridView1.AllowSorting = false;
GridView1.Columns[2].Visible = false;
//export process
GridView1.Visible = true;
GridView1.AllowSorting = true;




Thank for your information. I have try to add in the below code, but the problem still same....any idea??

                for (int i = gv.Columns.Count - 1; i >= 0; i--)

                {

                    if (gv.Columns[i].Visible == false)

                    {

                        gv.HeaderRow.Cells[i].Visible = false;

                        gv.FooterRow.Cells[i].Visible = false;

                    }

                    gv.Columns[i].Visible = false;

                }



Hi lansishao,


I have checked your code and to me, the method PrepareControlForExport(Control control) needs some refinement, actually when u replace different controls like link-buttons, dropdowns etc with LiteralControl controls, there you should check the visibility
of the actual control, if actual control is visible then you should replace it with Literal otherwise no need to add it. Hopefully you got my point,


else if (current is CheckBox && current.Visible)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
}
// Controls has been replace with Literal and Literal is alwasy Visible :)
else if (current.Visible == false)
{
control.Controls.Remove(current);
}







Thanks 



Thank for your information. But actually i no so understand what you mean. Can you provide me some sample of code? thank you.



here it is,code id Bold and and under-lined


else if (current is CheckBox && current.Visible) // visibility check
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
}
// Controls has been replace with Literal and Literal is alwasy Visible :)
else if (current.Visible == false)
{
control.Controls.Remove(current);
}



Thank you...but after i try ur method add on the code, after export the data to excel, those hidden column still show....
Cry



can you share the ASPX page code, where you are hiding the grid columns, like grid item template and specially the hidden column template.


thanks



this is sample as below:




        EnableModelValidation="True" CellPadding="4" ForeColor="#333333" GridLines="Vertical"             

        style="font-family: 'Century Gothic'; font-size: small" Width="98%" ShowFooter="True"

        OnPreRender = "gv_PreRender" OnRowDataBound = "gv_RowDataBound">

   

   

                   
                        ItemStyle-HorizontalAlign="Right"/>

                       

                       

                           

                       


                       


                   
                        ItemStyle-HorizontalAlign="Right"/>

                       

                       

                           

                       


                       


   



change your hidden item template as follow,




ItemStyle-HorizontalAlign="Right"/>


Visible = "false" runat="server" Text='<%#Eval("Jan") %>'>


ItemStyle-HorizontalAlign="Right"/>


Visible = "false" runat="server" Text='<%#Eval("Feb") %>'>










thanks for you...i have set the label to visible and the problem solved..


because it have many page...may i know any best way to amend the code what i post before?



it is good to know that your problem solved, please mark the thread as answered if it helps you Innocent


Secondly, in your code you are checking at control Level that if it is visible or not, your code line


if(control.visible==false)

so you have to apply the visible attribute to every control in every grid in every page, other wise chagne the code to export data, that change of code, may introduce other problems :) 




[RESOLVED] Grid View Update


Dear Friends,


                 I am inserting data from grid using button control. Hence there is no Button controls inside the grid.


When loading the grid at first time initially first row will be there and if i click the "Add" button means rows will create. For this my code part is,


#region SetInitialRowforTransfer

///



/// SetInitialRowforTransfer

///


private void SetInitialRowforTransfer()

{

try

{

DataTable dt = new DataTable();


DataRow dr = null;


dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));


dt.Columns.Add(new DataColumn("Column1", typeof(string)));


dt.Columns.Add(new DataColumn("Column2", typeof(string)));


dt.Columns.Add(new DataColumn("Column3", typeof(string)));


dt.Columns.Add(new DataColumn("Column4", typeof(string)));


dt.Columns.Add(new DataColumn("Column5", typeof(string)));


dt.Columns.Add(new DataColumn("Column6", typeof(string)));


dt.Columns.Add(new DataColumn("Column7", typeof(string)));


dr = dt.NewRow();


dr["RowNumber"] = 1;


dr["Column1"] = string.Empty;


dr["Column2"] = string.Empty;


dr["Column3"] = string.Empty;


dr["Column4"] = string.Empty;


dr["Column5"] = string.Empty;


dr["Column6"] = string.Empty;


dr["Column7"] = string.Empty;


dt.Rows.Add(dr);


//dr = dt.NewRow();



//Store the DataTable in ViewState


ViewState["CurrentTableforTransfer"] = dt;



gvContact.DataSource = dt;


gvContact.DataBind();

}

catch (Exception ex)

{


throw ex;

}




}

#endregion


#region AddNewRowToGridforTransfer

///



/// AddNewRowToGridforTransfer

///


private void AddNewRowToGridforTransfer()

{

try

{


int rowIndex = 0;



if (ViewState["CurrentTableforTransfer"] != null)

{


DataTable dtCurrentTable = (DataTable)ViewState["CurrentTableforTransfer"];


DataRow drCurrentRow = null;


if (dtCurrentTable.Rows.Count > 0)

{


for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)

{


//extract the TextBox values


TextBox box1 = (TextBox)gvContact.Rows[rowIndex].Cells[1].FindControl("txtTransferPLaceFrom");


TextBox box2 = (TextBox)gvContact.Rows[rowIndex].Cells[2].FindControl("txtDesignTransfer");


TextBox box3 = (TextBox)gvContact.Rows[rowIndex].Cells[3].FindControl("txtTansferDate");


TextBox box4 = (TextBox)gvContact.Rows[rowIndex].Cells[4].FindControl("txtToPlace");


TextBox box5 = (TextBox)gvContact.Rows[rowIndex].Cells[5].FindControl("txtJoiningDate");


TextBox box6 = (TextBox)gvContact.Rows[rowIndex].Cells[6].FindControl("txtTransferReason");


TextBox box7 = (TextBox)gvContact.Rows[rowIndex].Cells[7].FindControl("txtTransferemail");



drCurrentRow = dtCurrentTable.NewRow();


drCurrentRow["RowNumber"] = i + 1;



dtCurrentTable.Rows[i - 1]["Column1"] = box1.Text;


dtCurrentTable.Rows[i - 1]["Column2"] = box2.Text;


dtCurrentTable.Rows[i - 1]["Column3"] = box3.Text;


dtCurrentTable.Rows[i - 1]["Column4"] = box4.Text;


dtCurrentTable.Rows[i - 1]["Column5"] = box5.Text;


dtCurrentTable.Rows[i - 1]["Column6"] = box6.Text;


dtCurrentTable.Rows[i - 1]["Column7"] = box7.Text;



rowIndex++;


}


dtCurrentTable.Rows.Add(drCurrentRow);


ViewState["CurrentTableforTransfer"] = dtCurrentTable;



gvContact.DataSource = dtCurrentTable;


gvContact.DataBind();


}


}


else

{


Response.Write("ViewState is null");


}



//Set Previous Data on Postbacks


SetPreviousDataforTransfer();

}

catch (Exception ex)

{


throw ex;

}


}

#endregion


#region SetPreviousDataforTransfer

///



/// SetPreviousDataforTransfer

///


private void SetPreviousDataforTransfer()

{


try

{

int rowIndex = 0;


if (ViewState["CurrentTableforTransfer"] != null)

{


DataTable dt = (DataTable)ViewState["CurrentTableforTransfer"];


if (dt.Rows.Count > 0)

{


for (int i = 0; i < dt.Rows.Count; i++)

{


TextBox box1 = (TextBox)gvContact.Rows[rowIndex].Cells[1].FindControl("txtTransferPLaceFrom");


TextBox box2 = (TextBox)gvContact.Rows[rowIndex].Cells[2].FindControl("txtDesignTransfer");


TextBox box3 = (TextBox)gvContact.Rows[rowIndex].Cells[3].FindControl("txtTansferDate");


TextBox box4 = (TextBox)gvContact.Rows[rowIndex].Cells[4].FindControl("txtToPlace");


TextBox box5 = (TextBox)gvContact.Rows[rowIndex].Cells[5].FindControl("txtJoiningDate");


TextBox box6 = (TextBox)gvContact.Rows[rowIndex].Cells[6].FindControl("txtTransferReason");


TextBox box7 = (TextBox)gvContact.Rows[rowIndex].Cells[7].FindControl("txtTransferemail");




box1.Text = dt.Rows[i]["Column1"].ToString();


box2.Text = dt.Rows[i]["Column2"].ToString();


box3.Text = dt.Rows[i]["Column3"].ToString();


box4.Text = dt.Rows[i]["Column4"].ToString();


box5.Text = dt.Rows[i]["Column5"].ToString();


box6.Text = dt.Rows[i]["Column6"].ToString();


box7.Text = dt.Rows[i]["Column7"].ToString();



rowIndex++;


}


}


}


}

catch (Exception ex)

{


throw ex;

}

}

#endregion


#region ButtonAddfoTransfer_Click

///



/// ButtonAddfoTransfer_Click

///


///

///

protected void ButtonAddfoTransfer_Click(object sender, EventArgs e)

{


AddNewRowToGridforTransfer();


}

#endregion



Then i can insert the data by using following Insert code,


#region InsertGridTransferDetails


public void InsertGridTransferDetails(int sid)

{

BO_ObjSupplierMaster = new BO_Supplier_Master();

BE_ObjSupplierContact = new BE_Supplier_Contact();

try

{


foreach (GridViewRow row in gvContact.Rows)

{


TextBox txtplacefrm = (TextBox)row.FindControl("txtTransferPLaceFrom");

TextBox txtdesigntransfer = (TextBox)row.FindControl("txtDesignTransfer");

TextBox txttransferdate = (TextBox)row.FindControl("txtTansferDate");

TextBox txttoplace = (TextBox)row.FindControl("txtToPlace");

TextBox txtjoindate = (TextBox)row.FindControl("txtJoiningDate");

TextBox txttransferreason = (TextBox)row.FindControl("txtTransferReason");

TextBox txttransferemail = (TextBox)row.FindControl("txtTransferemail");


BE_ObjSupplierContact.Sup_Con_Lname1 = txtplacefrm.Text;

BE_ObjSupplierContact.Sup_Con_Mname1 = txtdesigntransfer.Text;

BE_ObjSupplierContact.Sup_Con_Fname1 = txttransferdate.Text;


BE_ObjSupplierContact.Sup_Con_Title1 = txttoplace.Text;

BE_ObjSupplierContact.Sup_Con_Telephone1 = txtjoindate.Text;

BE_ObjSupplierContact.Sup_Con_Mob1 = txttransferreason.Text;

BE_ObjSupplierContact.Sup_Con_Email1 = txttransferemail.Text;


BE_ObjSupplierContact.Sup_Master_Key1 = Convert.ToInt16(sid);


BO_ObjSupplierMaster.InsertSupplierContact(BE_ObjSupplierContact);


}





}

catch (Exception ex)

{


throw ex;

}

}

#endregion



Front end code is,



BorderColor="#A01E1E" Width="85%" HeaderStyle-Height="40px" RowStyle-Height="30px"

RowStyle-BorderColor="#A01E1E" runat="server" ShowFooter="true" AutoGenerateColumns="false">
















































































Text="Add" />









Now i want to Update the record. How can i bind the data to the grid. Please guide me to bind the data.



hey, once you add a new row to datatable, you can rebind the datatable to gridview again as


gvContact.DataSource = dtCurrentTable;


gvContact.DataBind();



and it will automatically update record



Hi,


Goto following link it has shown insert,update and delete inline.


http://www.codeproject.com/Articles/24085/Insert-Update-Delete-with-Gridview-Simple-Way


[RESOLVED] Export ExcelFile to grid View


Hi, I want to import an excel file(file name: tp30.xls, having one sheet name: tp30) in a gridView. Every time I get a Exception....


Syntax error (missing operator) in query expression 'Valuated stock'.


near the line.....    da.Fill(ds);    ( or, da.Fill(ds,"[tp30$]"); )


here is my codes........


protected void Button2_Click(object sender, EventArgs e)
{
string connString = "";
string strFileType = Path.GetExtension(FileUpload1.FileName).ToLower();
string path = FileUpload1.PostedFile.FileName;
//Connection String to Excel Workbook
if (strFileType.Trim() == ".xls")
{
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
string query = "SELECT Material,Valuated stock FROM [tp30$]";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
da.Dispose();
conn.Close();
conn.Dispose();
}
}

The aspx code.....
































It simply does not understand that Valuated stock is one word and not 2 different names. 


Try


string query = "SELECT Material,[Valuated stock] FROM [tp30$]";


I have Solve it!!!



Hi San,

Try this

 string query = "SELECT Material,[Valuated stock] FROM [tp30$]";



Sql didn't allow space between the name of column.so you need to put the name in square bracket.

hope this will help you out .

[RESOLVED] Asp.net clickable chart control


Hi all...


I am new to asp.net . I created a chart control with data binding and it has one series. Now I need the chart to be clickable which navigates to another pages by clicking each area. I found this solution,


                         Chart3.Series["Series1"].Url="EffJaEla.aspx";


But, here all the areas(If it is a column chart, all the columns are navigating to "EffJaEla.aspx" only) are navigatin to one page. I need to navigate to different pages by clicking columns. If the chart is with 4 columns, I need to navigate to 4 pages by
clicking 4 columns. Please help me...



Hi ThiTha,


Microsofts  chart control definitely does support click-through. Check below article out at 4guysfromrolla.


http://www.4guysfromrolla.com/articles/102809-1.aspx


And for more articles please have a look at the threads below


http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418


http://forums.asp.net/t/1551832.aspx/1


http://forums.asp.net/t/1802726.aspx/1


http://www.advsofteng.com/doc/cdnetdoc/simpleclickable.htm


Hope this helps.


Thanks,


Jatin



here is the similar thread post,


http://forums.asp.net/t/1551832.aspx/1



Hi jats...


Actually I went through these links....but I couldn't find an answere...


Here is my design...


 

         BackColor="64, 64, 0" Palette="Chocolate" onload="Chart2_Load">

            

                

                  LegendText="EFFICIENCY" Palette="BrightPastel">

                 

                


            


            

            

            


            

                

                


            


        




    ConnectionString="<%$ ConnectionStrings:KPIConnectionString1 %>"

    SelectCommand="SELECT [Efficiency], [Fty] FROM [Efficiency_Summery] WHERE ([TransactionDate] = @TransactionDate) ORDER BY [Fty]">

   

    

   


  



There I bind data to the chart.....


then the chart is developped....


Assume I am in a column chart...


I have 4 columns in my chart... I need to click all these columns and navigate to 4 different pages with 4 columns...


Chart3.Series["Series1"].Url="EffJaEla.aspx";


This code navigates to one page by all 4 columns and it does not allow to use 4 urls...


I need to use 4 urls for 4 columns...


Hope you underestood this....


Please help me....



Thanks a lot...




Hi Ijas...


Actually I went through these links....but I couldn't find an answere...


Here is my design...


 

         BackColor="64, 64, 0" Palette="Chocolate" onload="Chart2_Load">

            

                

                  LegendText="EFFICIENCY" Palette="BrightPastel">

                 

                


            


            

            

            


            

                

                


            


        




    ConnectionString="<%$ ConnectionStrings:KPIConnectionString1 %>"

    SelectCommand="SELECT [Efficiency], [Fty] FROM [Efficiency_Summery] WHERE ([TransactionDate] = @TransactionDate) ORDER BY [Fty]">

   

    

   


  



There I bind data to the chart.....


then the chart is developped....


Assume I am in a column chart...


I have 4 columns in my chart... I need to click all these columns and navigate to 4 different pages with 4 columns...


Chart3.Series["Series1"].Url="EffJaEla.aspx";


This code navigates to one page by all 4 columns and it does not allow to use 4 urls...


I need to use 4 urls for 4 columns...


Hope you underestood this....


Please help me....



Thanks a lot...



Hi,


Do you refer the link
http://www.4guysfromrolla.com/articles/102809-1.aspx
? You can set the points url property in the chart control's databound event like this


Protected Sub chtCategoriesProductCount_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles chtCategoriesProductCount.DataBound
For Each point As DataPoint In chtCategoriesProductCount.Series("Categories").Points
Dim categoryId As Integer = point.YValues(1)
point.Url = String.Format("~/Demos/DrillDown/ProductsInCategory.aspx?CategoryID={0}", categoryId.ToString())
...
Next
End Sub

And refer the radchart control:


http://www.telerik.com/community/forums/aspnet-ajax/chart/create-chart-click-event.aspx


Hope it can help you