Click here to Skip to main content
15,918,243 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Gridview total number of rows Pin
srinandan..24-Nov-09 22:07
srinandan..24-Nov-09 22:07 
GeneralRe: Gridview total number of rows Pin
Satish Mahapatra24-Nov-09 22:22
Satish Mahapatra24-Nov-09 22:22 
GeneralRe: Gridview total number of rows Pin
srinandan..24-Nov-09 23:17
srinandan..24-Nov-09 23:17 
GeneralRe: Gridview total number of rows Pin
Nishant Singh25-Nov-09 0:50
Nishant Singh25-Nov-09 0:50 
QuestionRemove masterpage Pin
Subin Mavunkal24-Nov-09 18:47
Subin Mavunkal24-Nov-09 18:47 
AnswerRe: Remove masterpage Pin
Abhijit Jana24-Nov-09 18:52
professionalAbhijit Jana24-Nov-09 18:52 
QuestionProblem related to textbox Pin
Arun k. yadav24-Nov-09 18:29
Arun k. yadav24-Nov-09 18:29 
AnswerRe: Problem related to textbox Pin
Abhijit Jana24-Nov-09 18:53
professionalAbhijit Jana24-Nov-09 18:53 
GeneralRe: Problem related to textbox Pin
Anurag Gandhi24-Nov-09 20:39
professionalAnurag Gandhi24-Nov-09 20:39 
GeneralRe: Problem related to textbox Pin
April Fans24-Nov-09 22:58
April Fans24-Nov-09 22:58 
AnswerRe: Problem related to textbox Pin
Anurag Gandhi24-Nov-09 20:36
professionalAnurag Gandhi24-Nov-09 20:36 
QuestionApplication designing issue Pin
Amit Patel198524-Nov-09 18:16
Amit Patel198524-Nov-09 18:16 
AnswerRe: Application designing issue Pin
Abhijit Jana24-Nov-09 18:56
professionalAbhijit Jana24-Nov-09 18:56 
AnswerRe: Application designing issue Pin
Vimalsoft(Pty) Ltd24-Nov-09 19:27
professionalVimalsoft(Pty) Ltd24-Nov-09 19:27 
AnswerRe: Application designing issue Pin
carlecomm26-Nov-09 14:45
carlecomm26-Nov-09 14:45 
QuestionDetailsView Update Problem Pin
RajpootRohan24-Nov-09 18:11
professionalRajpootRohan24-Nov-09 18:11 
AnswerRe: DetailsView Update Problem Pin
Nishant Singh24-Nov-09 20:07
Nishant Singh24-Nov-09 20:07 
GeneralRe: DetailsView Update Problem Pin
RajpootRohan24-Nov-09 20:29
professionalRajpootRohan24-Nov-09 20:29 
GeneralRe: DetailsView Update Problem Pin
Nishant Singh24-Nov-09 21:20
Nishant Singh24-Nov-09 21:20 
GeneralRe: DetailsView Update Problem Pin
RajpootRohan24-Nov-09 23:10
professionalRajpootRohan24-Nov-09 23:10 
GeneralRe: DetailsView Update Problem Pin
sashidhar24-Nov-09 21:30
sashidhar24-Nov-09 21:30 
QuestionReal problem with GridView TemplateField Sorting Pin
Maxdd 724-Nov-09 6:30
Maxdd 724-Nov-09 6:30 
I have a big GridView (with, edit,update,delete and insert operations),(forgive all this code, I cant present my problem other way Cry | :((

The template field is like this: (the gridview has OnPageIndexChanging="GridView3_PageIndexChanging" OnSorting="GridView3_Sorting" AllowSorting="True" properties)

<asp:TemplateField HeaderText="Nome" SortExpression="Nome">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtname" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblname" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                        <asp:TextBox ID="txtNName" runat="server" width="75px" Visible='<%# (bool) show_hide_insert() %>'> </asp:TextBox>
                    </FooterTemplate>
                            </asp:TemplateField>


The Grid View is populated this way:

public void TempTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID", typeof(int));
        dt.Columns.Add("Name", typeof(String));
        dt.Columns.Add("Year", typeof(String));

// i've erased some colummns here

        dt.Columns.Add("Image", typeof(String));



        Session["data"] = dt;
        Temp = dt.Copy();
      
// query. ...

        DataSet ds = GetData(query);
        GridView3.DataSource = ds;
        GridView3.DataBind();

    }

DataSet GetData(String queryString)
    {

        string connectionString;
        connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
        DataSet ds = new DataSet();

        try
        {
         
            SqlConnection Conn = new SqlConnection(connectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(queryString, connectionString);
            adapter.Fill(ds);

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);

        }

        return ds;
    }

public DataTable Temp
    {
        get
        {
            object o = ViewState["Temp"];
            if (o == null)
            {
                DataTable dt = new DataTable();
                return dt;
            }
            else
                return (DataTable)o;
        }
        set
        {
            ViewState["Temp"] = value;
        }
    }


And then I'm trying to sort this way:

private string ConvertSortDirectionToSql(SortDirection sortDirection)
    {
        string newSortDirection = String.Empty;

        switch (sortDirection)
        {
            case SortDirection.Ascending:
                newSortDirection = "ASC";
                break;

            case SortDirection.Descending:
                newSortDirection = "DESC";
                break;
        }

        return newSortDirection;
    }

    protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        
        GridView3.PageIndex = e.NewPageIndex;
        GridView3.DataBind();
    }

    protected void GridView3_Sorting(object sender, GridViewSortEventArgs e)
    {
        DataTable dataTable = GridView3.DataSource as DataTable;

        if (dataTable != null)
        {
            DataView dataView = new DataView(dataTable);
            dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

            GridView3.DataSource = dataView;
            GridView3.DataBind();
        }
    }


I think its because I'm using the temporary table, but dont know how to aply that here on sorting... Can you help me please?
AnswerRe: Real problem with GridView TemplateField Sorting Pin
Maxdd 724-Nov-09 7:31
Maxdd 724-Nov-09 7:31 
GeneralRe: Real problem with GridView TemplateField Sorting Pin
Christian Graus24-Nov-09 7:32
protectorChristian Graus24-Nov-09 7:32 
GeneralRe: Real problem with GridView TemplateField Sorting [modified] Pin
Maxdd 724-Nov-09 10:33
Maxdd 724-Nov-09 10:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.