Search code examples
asp.netdatasetrepeater

how to change the column (dataset)value names in repeater


how to change the column (dataset)value names in repeater.

Repeater1.DataSource = ds;
Repeater1.DataBind();

<%# DataBinder.Eval(Container, "DataItem.BILLTYPE")%>

this my second column 'bill Type' now getting values 0, 1 like that.

if it is "0" i want to diplay as a "R.Cash" and if it is "1" i want to diplay as a "R.Credit"

i'm trying using for loop, still didnt get. please help me to change the column values.


Solution

  • Replace your below line

    <%# DataBinder.Eval(Container, "DataItem.BILLTYPE")%>
    

    with

    <%# Convert.ToString(DataBinder.Eval(Container, "DataItem.BILLTYPE")) == "0" ? "R.Cash" : "R.Credit" %>
    

    For more values, you have to create below public method in your .cs file.

    Public Method:

    public string getBillType(string fsNumber)
    {
        string lsBillType = string.Empty;
        switch (fsNumber)
        {
            case "0":
                lsBillType = "R.Cash";
                break;
            case "1":
                lsBillType = "R.Credit";
                break;
            case "2":
                lsBillType = "W.Credit";
                break;
            case "3":
                lsBillType = "S.Credit";
                break;
        }
    
        return lsBillType;
    }
    

    DataBinder:

    <%# getBillType(Convert.ToString(DataBinder.Eval(Container, "DataItem.BILLTYPE"))) %>