Hi,

I'm having problems applying my 'AsciiToString' function to the DataView. I tried this AsciiToString(filter); but that did not work because the text 'publisher LIKE' was in the way. Any idea how I can remove that from my filtered string? Thanks.

private void BindRepeater(string term)
    {
        DataSet ds = (DataSet)Cache["InfoToFilter"];
        if (ds == null)
        {

            ds = GetInfoFromDB();
            Cache["InfoToFilter"] = ds;
        }

        DataView view = new DataView();
        view.Table = ds.Tables[0];    
        string filter = String.Format("publisher LIKE '{0}'", term);  
        view.RowFilter = filter;       
        GridView1.DataSource = view;
        GridView1.DataBind();
    }


private static string AsciiToString(string content)
    {
        string StrValue = "";
        while (content.Length > 0)
        {
            // convert each ASCII value to the actual character
            StrValue += System.Convert.ToChar(System.Convert.ToInt32(content.Substring(0, 3))).ToString();
            // Remove the converted value
            content = content.Substring(3, content.Length - 3);


        }
        content = StrValue;
        return content;
    }

Recommended Answers

All 3 Replies

Anyone?????????

what the function is doing ? what you want to show in gridview ? is content argument is your publisher ?

Let us know..

Hi,

I'm having problems applying my 'AsciiToString' function to the DataView. I tried this AsciiToString(filter); but that did not work because the text 'publisher LIKE' was in the way. Any idea how I can remove that from my filtered string? Thanks.

private void BindRepeater(string term)
    {
        DataSet ds = (DataSet)Cache["InfoToFilter"];
        if (ds == null)
        {

            ds = GetInfoFromDB();
            Cache["InfoToFilter"] = ds;
        }

        DataView view = new DataView();
        view.Table = ds.Tables[0];    
        string filter = String.Format("publisher LIKE '{0}'", term);  
        view.RowFilter = filter;       
        GridView1.DataSource = view;
        GridView1.DataBind();
    }


private static string AsciiToString(string content)
    {
        string StrValue = "";
        while (content.Length > 0)
        {
            // convert each ASCII value to the actual character
            StrValue += System.Convert.ToChar(System.Convert.ToInt32(content.Substring(0, 3))).ToString();
            // Remove the converted value
            content = content.Substring(3, content.Length - 3);


        }
        content = StrValue;
        return content;
    }

I've posted some more code. Here is a description of what it does:
I have a dropdown box that gets populated with book names.
Before I display those items in the dropdown box I convert them first from Ascii to String. (Items in database are in ascii).
Then, on dropdownbox_SelectedIndexChanged, I populate the gridview based on the drop down's list selected value.
For example if the user selects book name 'Asp.net' from the dropdownbox, then I would want to populate my gridview with books that have that name.
My code below works fine, it populates my gridview based on what was selected in the dropdownbox.

Here is my problem:
Instead of displaying the string 'Asp.net' in the gridview, it displays the ascii version. The gridview is populated with numbers.
What I would like to do is apply my AsciiToString() function to the data before I display it in the gridview. How can I do that???
Thank you.

 

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

LoadSearchList();

}

}

 

private void LoadSearchList()

{

DataSet ds = (DataSet)Cache["InfoToFilter"];


if (ds == null)

{

ds = GetInfoFromDB();

Cache["InfoToFilter"] = ds;

}

//Populate the list of categories 

bookList.DataSource = ds;

bookList.DataValueField = "book";

bookList.DataTextField = "book";

bookList.DataBind();

for (int i = 0; i < bookList.Items.Count; i++)

{

bookList.Items[i].Text = AsciiToString(bookList.Items[i].Text);


}


}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

BindRepeater(StringToAscii(bookList.SelectedItem.Text));

}



private void BindRepeater(string term)

{


DataSet ds = (DataSet)Cache["InfoToFilter"];

if (ds == null)

{

ds = GetInfoFromDB();


Cache["InfoToFilter"] = ds;

}

DataView view = new DataView();

view.Table = ds.Tables[0];

string filter = String.Format("book LIKE '{0}'", term);

view.RowFilter = filter;

GridView1.DataSource = view;


GridView1.DataBind();

}



private static string AsciiToString(string content)

{

string StrValue = "";

while (content.Length > 0)

{

// convert each ASCII value to the actual character

StrValue += System.Convert.ToChar(System.Convert.ToInt32(content.Substring(0, 3))).ToString();

// Remove the converted value

content = content.Substring(3, content.Length - 3); 

}

content = StrValue;

return content;

}  
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.