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

2014年7月13日 星期日

[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] 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] 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] prevent show image button


I bound image button to data in datalist, (image url saved) How to prevent show image button when data have not image.(image url=empty) because in this case (image url=empty) the image button show whit no image whit X

bind Visible property of the button like this


Visible ='<%# Eval("ImageUrl") == System.DbNull.Value ? False : True %>'







oned_gk



bind Visible property of the button like this
Visible ='<%# Eval("ImageUrl") == System.DbNull.Value ? False : True %>'





This is not work:




VB?


Try this


Visible ='<%# Not Isdbnull(Eval("ImageUrl")) %>'









oned_gk



VB?
Try this
Visible ='<%# Not Isdbnull(Eval("ImageUrl")) %>'







this is not work, when the imagurl = null the imagebutton show whit X



protected void dlstControl_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{

((ImageButton)e.Item.Controls[Your ImageButton Index]).Visible =
((YourDataSourceType)e.Item.DataItem).ImageUrlProperty == null ? true : false;

//OR
((ImageButton)e.Item.Controls[Your ImageButton Index]).Visible =
((ImageButton)e.Item.Controls[Your ImageButton Index]).ImageUrl == null ? true : false;
}
}





mehr_83



this is not work, when the imagurl = null the imagebutton show whit X





Make sure the value is null instead empty string


For empty string try this


Visible ='<%# IIF(Eval("ImageUrl")="",false,true) %>'









oned_gk



VB?
Try this
Visible ='<%# Not Isdbnull(Eval("ImageUrl")) %>'







excuse me, this is work.


but


how to check the imagurl isempty and not checkto null



Make all empty string


ISNULL(IMAGEURL,'') as IMG


String.IsNullOrEmpty(Convert.ToString(Eval("ImageUrl")))? ...






[RESOLVED] How to bind DataList control within Web method in asp.net


Hi,


Can anyone help me in how to bind values to the datalist with in web method.


thanks



Hi,


That may not be possible. WebMethod or PageMethod are used to inform server or get data only


but not to create asp.net control or update it.


What u can do is, call WebMethod get DataSet and fill DataList at serverside itself.


http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html


or fill it by Ajax,


http://www.aspsnippets.com/Articles/Populate-ASPNet-DataList-by-binding-DataSet-Client-Side-using-jQuery-AJAX.aspx




Yes as raju has explained that web-methods are kind of Web-API calls and only service raw data not the server-side control binding etc. So, instead use jQuery based data control along with your web-methods.


Thanks 


[RESOLVED] Gridview Header Options


I was wondering if there are any additional header options for a gridview?


I have a grid whos query brings back 4 pieces of information for each of the past 6 months.


So it resembles:


Curr...Prev...Diff...% |  Curr...Prev...Diff...% | Curr...Prev....Diff...%  etc. 


The caption is being used for the name of the grid. But above each group of Curr...Prev...Diff...%, I want to show what month it represents.


So it would look like this:



..............June................|..............May..................|..............April...............|  etc.

Curr...Prev...Diff...% |  Curr...Prev...Diff...% | Curr...Prev....Diff...%  etc. 


 


What are my options?  I  guess I could use the caption area and the put the name of the grid above it in a label.


But this will only look good if I predifine these fields as fixed fields so they don't shrink or grow depending on the data.


But are there any other options, like sub headers group headers in a gridview?


Thanks!



Instead of Grid, Use
DataList
control.


Set RepeatDirection to Horizontal and Set RepeatColumns to 6


Make your custom layout where you put heading of Month and below it show its details.


Regards


[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] 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] 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] prevent show image button


I bound image button to data in datalist, (image url saved) How to prevent show image button when data have not image.(image url=empty) because in this case (image url=empty) the image button show whit no image whit X

bind Visible property of the button like this


Visible ='<%# Eval("ImageUrl") == System.DbNull.Value ? False : True %>'







oned_gk



bind Visible property of the button like this
Visible ='<%# Eval("ImageUrl") == System.DbNull.Value ? False : True %>'





This is not work:




VB?


Try this


Visible ='<%# Not Isdbnull(Eval("ImageUrl")) %>'









oned_gk



VB?
Try this
Visible ='<%# Not Isdbnull(Eval("ImageUrl")) %>'







this is not work, when the imagurl = null the imagebutton show whit X



protected void dlstControl_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{

((ImageButton)e.Item.Controls[Your ImageButton Index]).Visible =
((YourDataSourceType)e.Item.DataItem).ImageUrlProperty == null ? true : false;

//OR
((ImageButton)e.Item.Controls[Your ImageButton Index]).Visible =
((ImageButton)e.Item.Controls[Your ImageButton Index]).ImageUrl == null ? true : false;
}
}





mehr_83



this is not work, when the imagurl = null the imagebutton show whit X





Make sure the value is null instead empty string


For empty string try this


Visible ='<%# IIF(Eval("ImageUrl")="",false,true) %>'









oned_gk



VB?
Try this
Visible ='<%# Not Isdbnull(Eval("ImageUrl")) %>'







excuse me, this is work.


but


how to check the imagurl isempty and not checkto null



Make all empty string


ISNULL(IMAGEURL,'') as IMG


String.IsNullOrEmpty(Convert.ToString(Eval("ImageUrl")))? ...






[RESOLVED] How to bind DataList control within Web method in asp.net


Hi,


Can anyone help me in how to bind values to the datalist with in web method.


thanks



Hi,


That may not be possible. WebMethod or PageMethod are used to inform server or get data only


but not to create asp.net control or update it.


What u can do is, call WebMethod get DataSet and fill DataList at serverside itself.


http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html


or fill it by Ajax,


http://www.aspsnippets.com/Articles/Populate-ASPNet-DataList-by-binding-DataSet-Client-Side-using-jQuery-AJAX.aspx




Yes as raju has explained that web-methods are kind of Web-API calls and only service raw data not the server-side control binding etc. So, instead use jQuery based data control along with your web-methods.


Thanks 


[RESOLVED] Gridview Header Options


I was wondering if there are any additional header options for a gridview?


I have a grid whos query brings back 4 pieces of information for each of the past 6 months.


So it resembles:


Curr...Prev...Diff...% |  Curr...Prev...Diff...% | Curr...Prev....Diff...%  etc. 


The caption is being used for the name of the grid. But above each group of Curr...Prev...Diff...%, I want to show what month it represents.


So it would look like this:



..............June................|..............May..................|..............April...............|  etc.

Curr...Prev...Diff...% |  Curr...Prev...Diff...% | Curr...Prev....Diff...%  etc. 


 


What are my options?  I  guess I could use the caption area and the put the name of the grid above it in a label.


But this will only look good if I predifine these fields as fixed fields so they don't shrink or grow depending on the data.


But are there any other options, like sub headers group headers in a gridview?


Thanks!



Instead of Grid, Use
DataList
control.


Set RepeatDirection to Horizontal and Set RepeatColumns to 6


Make your custom layout where you put heading of Month and below it show its details.


Regards


[RESOLVED] Checkbox


i,ve a repeater


then datalist


and then checkbox,textbox and redaio button



                    runat="server">




<%#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())%>
]





<%-- ID="chkItemOptionalModifiers" OnSelectedIndexChanged="chkItemOptionalModifiers_SelectedIndexChanged"
runat="server">
--%>














LH
Full
RH







how i can get the valuse of textbox,checkbox,hiddenfiels.... in jquery..





hi nafees,


as you have used css-classes for both check-box and text-box, so, you can use these with jQuery selectors, like this,


$(".chkList").each( function(){ //your code } );
$(".spinnnerOptional").each( function(){ //your code } );

thanks


[RESOLVED] How to use jquery efect on DataList control of asp.net


Hi,


I want to apply jquery effect on DataList view's Item template.For example, when i mouse hover on the template ,button and others effect will appear .




Try the code shown in the link below. But, you need to customize it to your needs. It would help you understand the technique you need to follow to accomplish the task you need to do


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



hi,


I made a test . you can try it .


















code behind:


 public partial class MyDataList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List list = new List(){
new Student{StudentID="1111"},new Student{StudentID="2222"},
new Student{StudentID="333"},new Student{StudentID="444"},
new Student{StudentID="555"},new Student{StudentID="666"}
};
DataList1.DataSource = list;

DataList1.DataBind();
}
}
}
public class Student
{
private string studentID;

public string StudentID
{
get { return studentID; }
set { studentID = value; }
}
private string studentName;

public string StudentName
{
get { return studentName; }
set { studentName = value; }
}
}




if I repeat the column 3, the button appears in every item of the row.


I want to show the Button on a individual item , when i repeat column...



please help me.


[RESOLVED] Updating dropdown list in the datalist


Hi there,


I have a datalist where by have a dropdown list that populate from database. But when I update the information, the system giving me this error:


System.NullReferenceException: Object reference not set to an instance of an object.


And focus in this line 


String Category =  ((DropDownList)e.Item.FindControl("Category")).Text;

Below is my code:


                            RepeatColumns="1" DataKeyField="ID" 
class="Full-table" CellPadding="4" ForeColor="#333333"
OnItemDataBound="dlPromotionList_ItemDataBound"
OnEditCommand="dlPromotionList_EditCommand"
OnCancelCommand="dlPromotionList_CancelCommand"
OnDeleteCommand="dlPromotionList_DeleteCommand"
OnUpdateCommand="dlPromotionList_UpdateCommand"
>






















 


 


Category  

 
 





























 
 
Category  


   
 






Code behind: onItemBound


protected void dlPromotionList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList Category = (DropDownList)e.Item.FindControl("PromotionCategory");
String catID = ((Label)e.Item.FindControl("lblCat")).Text;

bindCat(Category, catID);

}
}

protected void bindCat(DropDownList Category, string catID) {
string sqlQuery;
// sqlQuery = " SELECT CategorySubID, CategorySubName FROM cs_CategorySubList WHERE CategorySubID = '" + catID + "' AND (Flag = 0) AND (Status = 0) AND CategoryID = 1";
sqlQuery = " SELECT CategorySubID, CategorySubName FROM cs_CategorySubList WHERE CategorySubID = '" + catID + "' AND CategorySubID != 11 AND (Flag = 0) AND (Status = 0) AND CategoryID = 1";
sqlQuery += " UNION SELECT CategorySubID, CategorySubName FROM cs_CategorySubList WHERE (Flag = 0) AND CategorySubID != 11 AND (Status = 0) AND CategoryID = 1";

using (SqlConnection conn = new SqlConnection(connection()))
{
try
{
SqlCommand cmd = new SqlCommand(sqlQuery, conn);
conn.Open();

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Category.DataSource = ds;
Category.DataTextField = "CategorySubName";
Category.DataValueField = "CategorySubID";
// professionlist.SelectedValue = ProfName;
int x = Convert.ToInt32(catID) - 1 ;
Category.SelectedIndex = x;
Category.DataBind();
}
catch (SqlException ex)
{
string msg = "Fetch Error: ";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}

}

on update:


protected void dlPromotionList_UpdateCommand(object source, DataListCommandEventArgs e)
{
getSession();
DateTime date = System.DateTime.Now;

string ID = Convert.ToString(dlPromotionList.DataKeys[e.Item.ItemIndex]);
String Title = ((TextBox)e.Item.FindControl("PromotionTitle")).Text;
String Description = ((TextBox)e.Item.FindControl("PromotionDescription")).Text;

String Category = ((DropDownList)e.Item.FindControl("Category")).Text;
String Url = ((TextBox)e.Item.FindControl("PromotionUrl")).Text;
String PromotionDeadline= ((TextBox)e.Item.FindControl("PromotionDeadline")).Text;
String PhotoID = ((Label)e.Item.FindControl("lblPromotionPhoto")).Text;
FileUpload promotionupload = ((FileUpload)e.Item.FindControl("PromotionPicUpload"));

FileUpload img = (FileUpload)promotionupload;
string fileExt = Path.GetExtension(promotionupload.FileName).ToLower();
string x;
string fn = "update";

if (img.HasFile && img.PostedFile != null)
{
deleteRowPromo(PhotoID);

if (fileExt != ".gif" || fileExt != ".jpg" || fileExt != ".jpeg" || fileExt != ".png" || fileExt != ".swf" || fileExt != ".bmp")
{
x = country + id + "+" + ipx + "+" + date + "+" + hour;
updatePic(img, fileExt, x);
savePromotionInformation(fn, ID);
}
else
{
string alert = "alert('You can upload only jpg ,jpg,gif,swf,bmp file');";
ScriptManager.RegisterStartupScript(this, GetType(), "JScript", alert, true);
}
}
using (SqlConnection con = new SqlConnection(connection()))
{
string query = "update ws_Offer set ";
query += " Name = @Title, Description = @Description, Price = @ActualPrice, PromotionDeadline=@PromotionDeadline, PromotionPrice = @PromotionPrice, Category = @Category, Url = @Url, LastModified=@LastModified, LastModifiedBy=@LastModifiedBy, LastModifiedFromIP=@LastModifiedFromIP";
query += " where ID = @ID";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Title", Title);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@ActualPrice", ActualPrice);
cmd.Parameters.AddWithValue("@PromotionPrice", PromotionPrice);
cmd.Parameters.AddWithValue("@PromotionDeadline", PromotionDeadline);
cmd.Parameters.AddWithValue("@Category", Category);
cmd.Parameters.AddWithValue("@Url", Url);
cmd.Parameters.AddWithValue("@LastModified", date);
cmd.Parameters.AddWithValue("@LastModifiedBy", HiddenGUIDx.Value);
cmd.Parameters.AddWithValue("@LastModifiedFromIP", ipx);
cmd.Parameters.AddWithValue("@ID", ID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

}
dlPromotionList.EditItemIndex = -1;
BinddlPromotionList();
}













Check the id of the control, make sure you type correct control id.


AFAIK, this is  PromotionCategory instead Category


Try this


DropDownList ddlcat=(DropDownList)e.Item.FindControl("PromotionCategory");
String Category = ddlcat.SelectedItem.Text;







Try this:


String Category = ((DropDownList)e.Item.FindControl("Category")).SelectedItem.Text;



 


[RESOLVED] Checkbox


i,ve a repeater


then datalist


and then checkbox,textbox and redaio button



                    runat="server">




<%#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())%>
]





<%-- ID="chkItemOptionalModifiers" OnSelectedIndexChanged="chkItemOptionalModifiers_SelectedIndexChanged"
runat="server">
--%>














LH
Full
RH







how i can get the valuse of textbox,checkbox,hiddenfiels.... in jquery..





hi nafees,


as you have used css-classes for both check-box and text-box, so, you can use these with jQuery selectors, like this,


$(".chkList").each( function(){ //your code } );
$(".spinnnerOptional").each( function(){ //your code } );

thanks


[RESOLVED] How to use jquery efect on DataList control of asp.net


Hi,


I want to apply jquery effect on DataList view's Item template.For example, when i mouse hover on the template ,button and others effect will appear .




Try the code shown in the link below. But, you need to customize it to your needs. It would help you understand the technique you need to follow to accomplish the task you need to do


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



hi,


I made a test . you can try it .


















code behind:


 public partial class MyDataList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List list = new List(){
new Student{StudentID="1111"},new Student{StudentID="2222"},
new Student{StudentID="333"},new Student{StudentID="444"},
new Student{StudentID="555"},new Student{StudentID="666"}
};
DataList1.DataSource = list;

DataList1.DataBind();
}
}
}
public class Student
{
private string studentID;

public string StudentID
{
get { return studentID; }
set { studentID = value; }
}
private string studentName;

public string StudentName
{
get { return studentName; }
set { studentName = value; }
}
}




if I repeat the column 3, the button appears in every item of the row.


I want to show the Button on a individual item , when i repeat column...



please help me.


[RESOLVED] Updating dropdown list in the datalist


Hi there,


I have a datalist where by have a dropdown list that populate from database. But when I update the information, the system giving me this error:


System.NullReferenceException: Object reference not set to an instance of an object.


And focus in this line 


String Category =  ((DropDownList)e.Item.FindControl("Category")).Text;

Below is my code:


                            RepeatColumns="1" DataKeyField="ID" 
class="Full-table" CellPadding="4" ForeColor="#333333"
OnItemDataBound="dlPromotionList_ItemDataBound"
OnEditCommand="dlPromotionList_EditCommand"
OnCancelCommand="dlPromotionList_CancelCommand"
OnDeleteCommand="dlPromotionList_DeleteCommand"
OnUpdateCommand="dlPromotionList_UpdateCommand"
>






















 


 


Category  

 
 





























 
 
Category  


   
 






Code behind: onItemBound


protected void dlPromotionList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList Category = (DropDownList)e.Item.FindControl("PromotionCategory");
String catID = ((Label)e.Item.FindControl("lblCat")).Text;

bindCat(Category, catID);

}
}

protected void bindCat(DropDownList Category, string catID) {
string sqlQuery;
// sqlQuery = " SELECT CategorySubID, CategorySubName FROM cs_CategorySubList WHERE CategorySubID = '" + catID + "' AND (Flag = 0) AND (Status = 0) AND CategoryID = 1";
sqlQuery = " SELECT CategorySubID, CategorySubName FROM cs_CategorySubList WHERE CategorySubID = '" + catID + "' AND CategorySubID != 11 AND (Flag = 0) AND (Status = 0) AND CategoryID = 1";
sqlQuery += " UNION SELECT CategorySubID, CategorySubName FROM cs_CategorySubList WHERE (Flag = 0) AND CategorySubID != 11 AND (Status = 0) AND CategoryID = 1";

using (SqlConnection conn = new SqlConnection(connection()))
{
try
{
SqlCommand cmd = new SqlCommand(sqlQuery, conn);
conn.Open();

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Category.DataSource = ds;
Category.DataTextField = "CategorySubName";
Category.DataValueField = "CategorySubID";
// professionlist.SelectedValue = ProfName;
int x = Convert.ToInt32(catID) - 1 ;
Category.SelectedIndex = x;
Category.DataBind();
}
catch (SqlException ex)
{
string msg = "Fetch Error: ";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}

}

on update:


protected void dlPromotionList_UpdateCommand(object source, DataListCommandEventArgs e)
{
getSession();
DateTime date = System.DateTime.Now;

string ID = Convert.ToString(dlPromotionList.DataKeys[e.Item.ItemIndex]);
String Title = ((TextBox)e.Item.FindControl("PromotionTitle")).Text;
String Description = ((TextBox)e.Item.FindControl("PromotionDescription")).Text;

String Category = ((DropDownList)e.Item.FindControl("Category")).Text;
String Url = ((TextBox)e.Item.FindControl("PromotionUrl")).Text;
String PromotionDeadline= ((TextBox)e.Item.FindControl("PromotionDeadline")).Text;
String PhotoID = ((Label)e.Item.FindControl("lblPromotionPhoto")).Text;
FileUpload promotionupload = ((FileUpload)e.Item.FindControl("PromotionPicUpload"));

FileUpload img = (FileUpload)promotionupload;
string fileExt = Path.GetExtension(promotionupload.FileName).ToLower();
string x;
string fn = "update";

if (img.HasFile && img.PostedFile != null)
{
deleteRowPromo(PhotoID);

if (fileExt != ".gif" || fileExt != ".jpg" || fileExt != ".jpeg" || fileExt != ".png" || fileExt != ".swf" || fileExt != ".bmp")
{
x = country + id + "+" + ipx + "+" + date + "+" + hour;
updatePic(img, fileExt, x);
savePromotionInformation(fn, ID);
}
else
{
string alert = "alert('You can upload only jpg ,jpg,gif,swf,bmp file');";
ScriptManager.RegisterStartupScript(this, GetType(), "JScript", alert, true);
}
}
using (SqlConnection con = new SqlConnection(connection()))
{
string query = "update ws_Offer set ";
query += " Name = @Title, Description = @Description, Price = @ActualPrice, PromotionDeadline=@PromotionDeadline, PromotionPrice = @PromotionPrice, Category = @Category, Url = @Url, LastModified=@LastModified, LastModifiedBy=@LastModifiedBy, LastModifiedFromIP=@LastModifiedFromIP";
query += " where ID = @ID";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Title", Title);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@ActualPrice", ActualPrice);
cmd.Parameters.AddWithValue("@PromotionPrice", PromotionPrice);
cmd.Parameters.AddWithValue("@PromotionDeadline", PromotionDeadline);
cmd.Parameters.AddWithValue("@Category", Category);
cmd.Parameters.AddWithValue("@Url", Url);
cmd.Parameters.AddWithValue("@LastModified", date);
cmd.Parameters.AddWithValue("@LastModifiedBy", HiddenGUIDx.Value);
cmd.Parameters.AddWithValue("@LastModifiedFromIP", ipx);
cmd.Parameters.AddWithValue("@ID", ID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

}
dlPromotionList.EditItemIndex = -1;
BinddlPromotionList();
}













Check the id of the control, make sure you type correct control id.


AFAIK, this is  PromotionCategory instead Category


Try this


DropDownList ddlcat=(DropDownList)e.Item.FindControl("PromotionCategory");
String Category = ddlcat.SelectedItem.Text;







Try this:


String Category = ((DropDownList)e.Item.FindControl("Category")).SelectedItem.Text;



 


[RESOLVED] Checkbox


i,ve a repeater


then datalist


and then checkbox,textbox and redaio button



                    runat="server">




<%#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())%>
]





<%-- ID="chkItemOptionalModifiers" OnSelectedIndexChanged="chkItemOptionalModifiers_SelectedIndexChanged"
runat="server">
--%>














LH
Full
RH







how i can get the valuse of textbox,checkbox,hiddenfiels.... in jquery..





hi nafees,


as you have used css-classes for both check-box and text-box, so, you can use these with jQuery selectors, like this,


$(".chkList").each( function(){ //your code } );
$(".spinnnerOptional").each( function(){ //your code } );

thanks